forked from googleapis/google-cloud-java
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement testPermission api of organizations (googleapis#125)
* feat: implement testPermission api of organization * feat: modified java doc * feat: modified java doc * feat: fix review changes * feat: fix javadoc
- Loading branch information
Showing
8 changed files
with
152 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- see http://mojo.codehaus.org/clirr-maven-plugin/examples/ignored-differences.html --> | ||
<differences> | ||
<difference> | ||
<className>com/google/cloud/resourcemanager/ResourceManager</className> | ||
<method>java.util.Map testOrgPermissions(java.lang.String, java.util.List)</method> | ||
<differenceType>7012</differenceType> | ||
</difference> | ||
<difference> | ||
<className>com/google/cloud/resourcemanager/spi/v1beta1/ResourceManagerRpc</className> | ||
<method>java.util.Map testOrgPermissions(java.lang.String, java.util.List)</method> | ||
<differenceType>7012</differenceType> | ||
</difference> | ||
</differences> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,9 @@ | |
import static org.junit.Assert.assertSame; | ||
import static org.junit.Assert.assertTrue; | ||
import static org.junit.Assert.fail; | ||
import static org.mockito.Mockito.doThrow; | ||
import static org.mockito.Mockito.verify; | ||
import static org.mockito.Mockito.when; | ||
|
||
import com.google.api.gax.paging.Page; | ||
import com.google.cloud.Identity; | ||
|
@@ -38,6 +41,7 @@ | |
import com.google.cloud.resourcemanager.testing.LocalResourceManagerHelper; | ||
import com.google.common.collect.ImmutableList; | ||
import com.google.common.collect.ImmutableMap; | ||
import java.io.IOException; | ||
import java.util.Iterator; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
@@ -46,7 +50,11 @@ | |
import org.junit.Before; | ||
import org.junit.BeforeClass; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.mockito.Mockito; | ||
import org.mockito.runners.MockitoJUnitRunner; | ||
|
||
@RunWith(MockitoJUnitRunner.class) | ||
public class ResourceManagerImplTest { | ||
|
||
private static final LocalResourceManagerHelper RESOURCE_MANAGER_HELPER = | ||
|
@@ -75,6 +83,9 @@ public class ResourceManagerImplTest { | |
.addIdentity(Role.editor(), Identity.serviceAccount("[email protected]")) | ||
.build(); | ||
|
||
private ResourceManagerRpcFactory rpcFactoryMock = Mockito.mock(ResourceManagerRpcFactory.class); | ||
private ResourceManagerRpc resourceManagerRpcMock = Mockito.mock(ResourceManagerRpc.class); | ||
|
||
@BeforeClass | ||
public static void beforeClass() { | ||
RESOURCE_MANAGER_HELPER.start(); | ||
|
@@ -456,4 +467,54 @@ public void testRuntimeException() { | |
assertEquals(exceptionMessage, exception.getCause().getMessage()); | ||
} | ||
} | ||
|
||
@Test | ||
public void testTestOrgPermissions() throws IOException { | ||
String organization = "organization/12345"; | ||
List<String> permissions = | ||
ImmutableList.of( | ||
"resourcemanager.organizations.get", "resourcemanager.organizations.getIamPolicy"); | ||
Map<String, Boolean> expected = | ||
ImmutableMap.of( | ||
"resourcemanager.organizations.get", | ||
true, | ||
"resourcemanager.organizations.getIamPolicy", | ||
false); | ||
when(rpcFactoryMock.create(Mockito.any(ResourceManagerOptions.class))) | ||
.thenReturn(resourceManagerRpcMock); | ||
ResourceManager resourceManager = | ||
ResourceManagerOptions.newBuilder() | ||
.setServiceRpcFactory(rpcFactoryMock) | ||
.build() | ||
.getService(); | ||
when(resourceManagerRpcMock.testOrgPermissions(organization, permissions)).thenReturn(expected); | ||
Map<String, Boolean> actual = resourceManager.testOrgPermissions(organization, permissions); | ||
assertEquals(expected, actual); | ||
verify(resourceManagerRpcMock).testOrgPermissions(organization, permissions); | ||
} | ||
|
||
@Test | ||
public void testTestOrgPermissionsWithResourceManagerException() throws IOException { | ||
String organization = "organizations/12345"; | ||
String exceptionMessage = "Not Found"; | ||
List<String> permissions = | ||
ImmutableList.of( | ||
"resourcemanager.organizations.get", "resourcemanager.organizations.getIamPolicy"); | ||
when(rpcFactoryMock.create(Mockito.any(ResourceManagerOptions.class))) | ||
.thenReturn(resourceManagerRpcMock); | ||
ResourceManager resourceManager = | ||
ResourceManagerOptions.newBuilder() | ||
.setServiceRpcFactory(rpcFactoryMock) | ||
.build() | ||
.getService(); | ||
doThrow(new ResourceManagerException(404, exceptionMessage)) | ||
.when(resourceManagerRpcMock) | ||
.testOrgPermissions(organization, permissions); | ||
try { | ||
resourceManager.testOrgPermissions(organization, permissions); | ||
} catch (ResourceManagerException expected) { | ||
assertEquals(404, expected.getCode()); | ||
assertEquals(exceptionMessage, expected.getMessage()); | ||
} | ||
} | ||
} |