Skip to content

Commit a829b26

Browse files
2 parents f8f0777 + e7f2a14 commit a829b26

3 files changed

Lines changed: 166 additions & 45 deletions

File tree

google-cloud-logging/src/test/java/com/google/cloud/logging/LoggingHandlerTest.java

Lines changed: 29 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,8 @@ public class LoggingHandlerTest {
159159
.append("com.google.cloud.logging.LoggingHandler.synchronicity=SYNC")
160160
.append(System.lineSeparator())
161161
.toString();
162+
private static final WriteOption[] DEFAULT_OPTIONS =
163+
new WriteOption[] {WriteOption.logName(LOG_NAME), WriteOption.resource(DEFAULT_RESOURCE)};
162164

163165
private Logging logging;
164166
private LoggingOptions options;
@@ -200,7 +202,7 @@ public void setUp() {
200202
public void afterClass() {
201203
EasyMock.verify(logging, options);
202204
}
203-
205+
204206

205207
private static LogRecord newLogRecord(Level level, String message) {
206208
LogRecord record = new LogRecord(level, message);
@@ -212,44 +214,31 @@ private static LogRecord newLogRecord(Level level, String message) {
212214
public void testPublishLevels() {
213215
EasyMock.expect(options.getProjectId()).andReturn(PROJECT).anyTimes();
214216
EasyMock.expect(options.getService()).andReturn(logging);
215-
logging.writeAsync(ImmutableList.of(FINEST_ENTRY), WriteOption.logName(LOG_NAME),
216-
WriteOption.resource(DEFAULT_RESOURCE));
217+
logging.writeAsync(ImmutableList.of(FINEST_ENTRY), DEFAULT_OPTIONS);
217218
EasyMock.expectLastCall().andReturn(ApiFutures.immediateFuture(null));
218-
logging.writeAsync(ImmutableList.of(FINER_ENTRY), WriteOption.logName(LOG_NAME),
219-
WriteOption.resource(DEFAULT_RESOURCE));
219+
logging.writeAsync(ImmutableList.of(FINER_ENTRY), DEFAULT_OPTIONS);
220220
EasyMock.expectLastCall().andReturn(ApiFutures.immediateFuture(null));
221-
logging.writeAsync(ImmutableList.of(FINE_ENTRY), WriteOption.logName(LOG_NAME),
222-
WriteOption.resource(DEFAULT_RESOURCE));
221+
logging.writeAsync(ImmutableList.of(FINE_ENTRY), DEFAULT_OPTIONS);
223222
EasyMock.expectLastCall().andReturn(ApiFutures.immediateFuture(null));
224-
logging.writeAsync(ImmutableList.of(CONFIG_ENTRY), WriteOption.logName(LOG_NAME),
225-
WriteOption.resource(DEFAULT_RESOURCE));
223+
logging.writeAsync(ImmutableList.of(CONFIG_ENTRY), DEFAULT_OPTIONS);
226224
EasyMock.expectLastCall().andReturn(ApiFutures.immediateFuture(null));
227-
logging.writeAsync(ImmutableList.of(INFO_ENTRY), WriteOption.logName(LOG_NAME),
228-
WriteOption.resource(DEFAULT_RESOURCE));
225+
logging.writeAsync(ImmutableList.of(INFO_ENTRY), DEFAULT_OPTIONS);
229226
EasyMock.expectLastCall().andReturn(ApiFutures.immediateFuture(null));
230-
logging.writeAsync(ImmutableList.of(WARNING_ENTRY), WriteOption.logName(LOG_NAME),
231-
WriteOption.resource(DEFAULT_RESOURCE));
227+
logging.writeAsync(ImmutableList.of(WARNING_ENTRY), DEFAULT_OPTIONS);
232228
EasyMock.expectLastCall().andReturn(ApiFutures.immediateFuture(null));
233-
logging.writeAsync(ImmutableList.of(SEVERE_ENTRY), WriteOption.logName(LOG_NAME),
234-
WriteOption.resource(DEFAULT_RESOURCE));
229+
logging.writeAsync(ImmutableList.of(SEVERE_ENTRY), DEFAULT_OPTIONS);
235230
EasyMock.expectLastCall().andReturn(ApiFutures.immediateFuture(null));
236-
logging.writeAsync(ImmutableList.of(DEBUG_ENTRY), WriteOption.logName(LOG_NAME),
237-
WriteOption.resource(DEFAULT_RESOURCE));
231+
logging.writeAsync(ImmutableList.of(DEBUG_ENTRY), DEFAULT_OPTIONS);
238232
EasyMock.expectLastCall().andReturn(ApiFutures.immediateFuture(null));
239-
logging.writeAsync(ImmutableList.of(NOTICE_ENTRY), WriteOption.logName(LOG_NAME),
240-
WriteOption.resource(DEFAULT_RESOURCE));
233+
logging.writeAsync(ImmutableList.of(NOTICE_ENTRY), DEFAULT_OPTIONS);
241234
EasyMock.expectLastCall().andReturn(ApiFutures.immediateFuture(null));
242-
logging.writeAsync(ImmutableList.of(ERROR_ENTRY), WriteOption.logName(LOG_NAME),
243-
WriteOption.resource(DEFAULT_RESOURCE));
235+
logging.writeAsync(ImmutableList.of(ERROR_ENTRY), DEFAULT_OPTIONS);
244236
EasyMock.expectLastCall().andReturn(ApiFutures.immediateFuture(null));
245-
logging.writeAsync(ImmutableList.of(CRITICAL_ENTRY), WriteOption.logName(LOG_NAME),
246-
WriteOption.resource(DEFAULT_RESOURCE));
237+
logging.writeAsync(ImmutableList.of(CRITICAL_ENTRY), DEFAULT_OPTIONS);
247238
EasyMock.expectLastCall().andReturn(ApiFutures.immediateFuture(null));
248-
logging.writeAsync(ImmutableList.of(ALERT_ENTRY), WriteOption.logName(LOG_NAME),
249-
WriteOption.resource(DEFAULT_RESOURCE));
239+
logging.writeAsync(ImmutableList.of(ALERT_ENTRY), DEFAULT_OPTIONS);
250240
EasyMock.expectLastCall().andReturn(ApiFutures.immediateFuture(null));
251-
logging.writeAsync(ImmutableList.of(EMERGENCY_ENTRY), WriteOption.logName(LOG_NAME),
252-
WriteOption.resource(DEFAULT_RESOURCE));
241+
logging.writeAsync(ImmutableList.of(EMERGENCY_ENTRY), DEFAULT_OPTIONS);
253242
EasyMock.expectLastCall().andReturn(ApiFutures.immediateFuture(null));
254243
EasyMock.replay(options, logging);
255244
Handler handler = new LoggingHandler(LOG_NAME, options);
@@ -313,14 +302,13 @@ public void enhanceLogEntry(Builder builder, LogRecord record) {
313302
handler.setFormatter(new TestFormatter());
314303
handler.publish(newLogRecord(Level.FINEST, MESSAGE));
315304
}
316-
305+
317306
@Test
318307
public void testReportFlushError() {
319308
EasyMock.expect(options.getProjectId()).andReturn(PROJECT).anyTimes();
320309
EasyMock.expect(options.getService()).andReturn(logging);
321310
RuntimeException ex = new RuntimeException();
322-
logging.writeAsync(ImmutableList.of(FINEST_ENTRY), WriteOption.logName(LOG_NAME),
323-
WriteOption.resource(DEFAULT_RESOURCE));
311+
logging.writeAsync(ImmutableList.of(FINEST_ENTRY), DEFAULT_OPTIONS);
324312
EasyMock.expectLastCall().andThrow(ex);
325313
EasyMock.replay(options, logging);
326314
ErrorManager errorManager = EasyMock.createStrictMock(ErrorManager.class);
@@ -359,8 +347,10 @@ public void testReportFormatError() {
359347
public void testFlushSize() {
360348
EasyMock.expect(options.getProjectId()).andReturn(PROJECT).anyTimes();
361349
EasyMock.expect(options.getService()).andReturn(logging);
362-
logging.writeAsync(ImmutableList.of(FINEST_ENTRY, FINER_ENTRY, FINE_ENTRY, CONFIG_ENTRY, INFO_ENTRY,
363-
WARNING_ENTRY), WriteOption.logName(LOG_NAME), WriteOption.resource(DEFAULT_RESOURCE));
350+
logging.writeAsync(
351+
ImmutableList.of(
352+
FINEST_ENTRY, FINER_ENTRY, FINE_ENTRY, CONFIG_ENTRY, INFO_ENTRY, WARNING_ENTRY),
353+
DEFAULT_OPTIONS);
364354
EasyMock.expectLastCall().andReturn(ApiFutures.immediateFuture(null));
365355
EasyMock.replay(options, logging);
366356
LoggingHandler handler = new LoggingHandler(LOG_NAME, options);
@@ -379,9 +369,10 @@ public void testFlushSize() {
379369
public void testFlushLevel() {
380370
EasyMock.expect(options.getProjectId()).andReturn(PROJECT).anyTimes();
381371
EasyMock.expect(options.getService()).andReturn(logging);
382-
logging.writeAsync(ImmutableList.of(FINEST_ENTRY, FINER_ENTRY, FINE_ENTRY, CONFIG_ENTRY, INFO_ENTRY,
383-
WARNING_ENTRY), WriteOption.logName(LOG_NAME),
384-
WriteOption.resource(DEFAULT_RESOURCE));
372+
logging.writeAsync(
373+
ImmutableList.of(
374+
FINEST_ENTRY, FINER_ENTRY, FINE_ENTRY, CONFIG_ENTRY, INFO_ENTRY, WARNING_ENTRY),
375+
DEFAULT_OPTIONS);
385376
EasyMock.expectLastCall().andReturn(ApiFutures.immediateFuture(null));
386377
EasyMock.replay(options, logging);
387378
LoggingHandler handler = new LoggingHandler(LOG_NAME, options);
@@ -426,8 +417,7 @@ public void testSyncWrite() {
426417
public void testAddHandler() {
427418
EasyMock.expect(options.getProjectId()).andReturn(PROJECT).anyTimes();
428419
EasyMock.expect(options.getService()).andReturn(logging);
429-
logging.writeAsync(ImmutableList.of(FINEST_ENTRY), WriteOption.logName(LOG_NAME),
430-
WriteOption.resource(DEFAULT_RESOURCE));
420+
logging.writeAsync(ImmutableList.of(FINEST_ENTRY), DEFAULT_OPTIONS);
431421
EasyMock.expectLastCall().andReturn(ApiFutures.immediateFuture(null));
432422
EasyMock.replay(options, logging);
433423
LoggingHandler handler = new LoggingHandler(LOG_NAME, options) {
@@ -483,15 +473,14 @@ public void testPropertiesFile() throws IOException, InterruptedException {
483473
assertEquals(LoggingLevel.CRITICAL, handler.getFlushLevel());
484474
assertEquals(Synchronicity.SYNC, handler.getSynchronicity());
485475

486-
LogManager.getLogManager().readConfiguration();
476+
LogManager.getLogManager().reset();
487477
}
488478

489479
@Test
490480
public void testClose() throws Exception {
491481
EasyMock.expect(options.getProjectId()).andReturn(PROJECT).anyTimes();
492482
EasyMock.expect(options.getService()).andReturn(logging);
493-
logging.writeAsync(ImmutableList.of(FINEST_ENTRY), WriteOption.logName(LOG_NAME),
494-
WriteOption.resource(DEFAULT_RESOURCE));
483+
logging.writeAsync(ImmutableList.of(FINEST_ENTRY), DEFAULT_OPTIONS);
495484
EasyMock.expectLastCall().andReturn(ApiFutures.immediateFuture(null));
496485
logging.close();
497486
EasyMock.expectLastCall().once();

google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/spi/v1/SubscriberImplTest.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,6 @@
5353
import org.junit.runner.RunWith;
5454
import org.junit.runners.Parameterized;
5555
import org.junit.runners.Parameterized.Parameters;
56-
import org.mockito.Mockito;
57-
import org.mockito.MockitoAnnotations;
5856

5957
/** Tests for {@link Subscriber}. */
6058
@RunWith(Parameterized.class)
@@ -162,10 +160,8 @@ public SubscriberImplTest(boolean streamingTest) {
162160

163161
@Before
164162
public void setUp() throws Exception {
165-
MockitoAnnotations.initMocks(this);
166-
167163
InProcessServerBuilder serverBuilder = InProcessServerBuilder.forName(testName.getMethodName());
168-
fakeSubscriberServiceImpl = Mockito.spy(new FakeSubscriberServiceImpl());
164+
fakeSubscriberServiceImpl = new FakeSubscriberServiceImpl();
169165
fakeExecutor = new FakeScheduledExecutorService();
170166
testChannelBuilder = InProcessChannelBuilder.forName(testName.getMethodName());
171167
serverBuilder.addService(fakeSubscriberServiceImpl);
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
/*
2+
* Copyright 2017 Google Inc. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.google.cloud.storage;
18+
19+
import com.google.cloud.Role;
20+
21+
/**
22+
* IAM roles specific to Storage. An overview of the permissions available to Storage and the
23+
* capabilities they grant can be found in the
24+
* <a href="https://cloud.google.com/storage/docs/access-control/iam">Google Cloud Storage IAM documentation.</a>
25+
*/
26+
public class StorageRoles {
27+
28+
/**
29+
* Grants the following permissions:
30+
* <ul>
31+
* <li>storage.buckets.*</li>
32+
* <li>storage.objects.*</li>
33+
* </ul>
34+
*/
35+
public static Role admin() {
36+
return Role.of("roles/storage.admin");
37+
}
38+
39+
/**
40+
* Grants the following permissions:
41+
* <ul>
42+
* <li>storage.objects.list</li>
43+
* <li>storage.objects.get</li>
44+
* </ul>
45+
*/
46+
public static Role objectViewer() {
47+
return Role.of("roles/storage.objectViewer");
48+
}
49+
50+
/**
51+
* Grants the following permissions:
52+
* <ul>
53+
* <li>storage.objects.create</li>
54+
* </ul>
55+
*/
56+
public static Role objectCreator() {
57+
return Role.of("roles/storage.objectCreator");
58+
}
59+
60+
/**
61+
* Grants the following permissions:
62+
* <ul>
63+
* <li>storage.objects.*</li>
64+
* </ul>
65+
*/
66+
public static Role objectAdmin() {
67+
return Role.of("roles/storage.objectAdmin");
68+
}
69+
70+
/**
71+
* Grants the following permissions:
72+
* <ul>
73+
* <li>storage.buckets.get</li>
74+
* <li>storage.buckets.update</li>
75+
* <li>storage.buckets.setIamPolicy</li>
76+
* <li>storage.buckets.getIamPolicy</li>
77+
* <li>storage.objects.list</li>
78+
* <li>storage.objects.create</li>
79+
* <li>storage.objects.delete</li>
80+
* </ul>
81+
*/
82+
public static Role legacyBucketOwner() {
83+
return Role.of("roles/storage.legacyBucketOwner");
84+
}
85+
86+
/**
87+
* Grants the following permissions:
88+
* <ul>
89+
* <li>storage.buckets.get</li>
90+
* <li>storage.objects.list</li>
91+
* <li>storage.objects.create</li>
92+
* <li>storage.objects.delete</li>
93+
* </ul>
94+
*/
95+
public static Role legacyBucketWriter() {
96+
return Role.of("roles/storage.legacyBucketWriter");
97+
}
98+
99+
/**
100+
* Grants the following permissions:
101+
* <ul>
102+
* <li>storage.buckets.get</li>
103+
* <li>storage.objects.list</li>
104+
* </ul>
105+
*/
106+
public static Role legacyBucketReader() {
107+
return Role.of("roles/storage.legacyBucketReader");
108+
}
109+
110+
/**
111+
* Grants the following permissions:
112+
* <ul>
113+
* <li>storage.objects.get</li>
114+
* <li>storage.objects.update</li>
115+
* <li>storage.objects.getIamPolicy</li>
116+
* <li>storage.objects.setIamPolicy</li>
117+
* </ul>
118+
*/
119+
public static Role legacyObjectOwner() {
120+
return Role.of("roles/storage.legacyObjectOwner");
121+
}
122+
123+
/**
124+
* Grants the following permissions:
125+
* <ul>
126+
* <li>storage.objects.get</li>
127+
* </ul>
128+
*/
129+
public static Role legacyObjectReader() {
130+
return Role.of("roles/storage.legacyObjectReader");
131+
}
132+
133+
private StorageRoles() {
134+
// Intentionally left blank.
135+
}
136+
}

0 commit comments

Comments
 (0)