private static void assertNoMatch(Policy expected, Policy actual) { assertFalse(new ApiPolicyMatcher(expected).matches(actual)); }
@Test public void testStaticMocker() { PolicyAcceptor mock = EasyMock.createMock(PolicyAcceptor.class); EasyMock.expect(mock.accept(eqApiPolicy(API_POLICY_1))).andReturn(0); EasyMock.replay(mock); mock.accept(API_POLICY_2); EasyMock.verify(mock); } }
public ApiPolicyMatcher(Policy expected) { expectedBindings = toMap(expected.getBindings()); expectedEtag = expected.getEtag(); }
public static Policy eqApiPolicy(Policy in) { EasyMock.reportMatcher(new ApiPolicyMatcher(in)); return null; }
@Override public boolean matches(Object object) { if (!(object instanceof Policy)) { return false; } Policy actual = (Policy) object; Map<String, Set<String>> actualBindings = toMap(actual.getBindings()); String actualEtag = actual.getEtag(); if (expectedEtag == null) { if (actualEtag != null) { return false; } } else { if (!expectedEtag.equals(actual.getEtag())) { return false; } } if (expectedBindings.size() != actualBindings.size()) { return false; } for (Map.Entry<String, Set<String>> entry : expectedBindings.entrySet()) { String role = entry.getKey(); Set<String> expectedMembers = entry.getValue(); Set<String> actualMembers = actualBindings.get(role); if (!expectedMembers.equals(actualMembers)) { return false; } } return true; }
private static void assertMatch(Policy expected, Policy actual) { assertTrue(new ApiPolicyMatcher(expected).matches(actual)); }
storageRpcMock.setIamPolicy( EasyMock.eq(BUCKET_NAME1), eqApiPolicy(preCommitApiPolicy), EasyMock.eq(EMPTY_RPC_OPTIONS))) .andReturn(postCommitApiPolicy);
assertTrue(new ApiPolicyMatcher(apiPolicy).matches(actualApiPolicy));