Repository: ambari Updated Branches: refs/heads/trunk 069cc49da -> 2fcc94753
http://git-wip-us.apache.org/repos/asf/ambari/blob/2fcc9475/ambari-server/src/test/java/org/apache/ambari/server/collections/functors/AndPredicateTest.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/collections/functors/AndPredicateTest.java b/ambari-server/src/test/java/org/apache/ambari/server/collections/functors/AndPredicateTest.java new file mode 100644 index 0000000..977fe9d --- /dev/null +++ b/ambari-server/src/test/java/org/apache/ambari/server/collections/functors/AndPredicateTest.java @@ -0,0 +1,108 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ambari.server.collections.functors; + +import org.apache.ambari.server.collections.Predicate; +import org.easymock.EasyMockSupport; +import org.junit.Assert; +import org.junit.Test; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + +import static org.easymock.EasyMock.expect; + +public class AndPredicateTest extends EasyMockSupport { + + @Test + public void testEvaluate() { + Predicate mockPredicate1 = createStrictMock(Predicate.class); + expect(mockPredicate1.evaluate("context")).andReturn(true).times(1); + expect(mockPredicate1.evaluate("context")).andReturn(false).times(1); + expect(mockPredicate1.evaluate("context")).andReturn(true).times(1); + + Predicate mockPredicate2 = createStrictMock(Predicate.class); + expect(mockPredicate2.evaluate("context")).andReturn(true).times(1); + expect(mockPredicate2.evaluate("context")).andReturn(true).times(1); + + replayAll(); + + AndPredicate predicate = new AndPredicate(mockPredicate1, mockPredicate2); + + // Try with true and true + predicate.evaluate("context"); + + // Try with false and ???? (short circuited) + predicate.evaluate("context"); + + // Try with true and false + predicate.evaluate("context"); + + verifyAll(); + + Assert.assertArrayEquals(new Predicate[]{mockPredicate1, mockPredicate2}, predicate.getPredicates()); + } + + @Test + public void testToMap() { + Predicate mockPredicate1 = createStrictMock(Predicate.class); + expect(mockPredicate1.toMap()).andReturn(Collections.<String, Object>singletonMap("nop", "foo")).times(1); + + Predicate mockPredicate2 = createStrictMock(Predicate.class); + expect(mockPredicate2.toMap()).andReturn(Collections.<String, Object>singletonMap("nop", "baz")).times(1); + + replayAll(); + + AndPredicate predicate = new AndPredicate(mockPredicate1, mockPredicate2); + Map<String, Object> actualMap = predicate.toMap(); + + verifyAll(); + + Map<String, Object> expectedMap = new HashMap<String, Object>(); + expectedMap.put("and", new ArrayList<Map<String, Object>>( + Arrays.asList(Collections.<String, Object>singletonMap("nop", "foo"), + Collections.<String, Object>singletonMap("nop", "baz")) + )); + + Assert.assertEquals(expectedMap, actualMap); + } + + @Test + public void testToJSON() { + Predicate mockPredicate1 = createStrictMock(Predicate.class); + expect(mockPredicate1.toMap()).andReturn(Collections.<String, Object>singletonMap("nop", "foo")).times(1); + + Predicate mockPredicate2 = createStrictMock(Predicate.class); + expect(mockPredicate2.toMap()).andReturn(Collections.<String, Object>singletonMap("nop", "baz")).times(1); + + replayAll(); + + AndPredicate predicate = new AndPredicate(mockPredicate1, mockPredicate2); + String actualJSON = predicate.toJSON(); + + verifyAll(); + + String expectedJSON = "{\"and\":[{\"nop\":\"foo\"},{\"nop\":\"baz\"}]}"; + + Assert.assertEquals(expectedJSON, actualJSON); + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ambari/blob/2fcc9475/ambari-server/src/test/java/org/apache/ambari/server/collections/functors/ContainsPredicateTest.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/collections/functors/ContainsPredicateTest.java b/ambari-server/src/test/java/org/apache/ambari/server/collections/functors/ContainsPredicateTest.java new file mode 100644 index 0000000..d27510f --- /dev/null +++ b/ambari-server/src/test/java/org/apache/ambari/server/collections/functors/ContainsPredicateTest.java @@ -0,0 +1,91 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ambari.server.collections.functors; + +import org.easymock.EasyMockSupport; +import org.junit.Assert; +import org.junit.Test; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +import static org.easymock.EasyMock.anyObject; +import static org.easymock.EasyMock.expect; + +public class ContainsPredicateTest extends EasyMockSupport { + + @Test + public void testEvaluate() { + Set<String> data1 = new HashSet<String>(Arrays.asList("ONE", "TWO", "THREE")); + Set<String> data2 = new HashSet<String>(Arrays.asList("TWO", "THREE")); + + ContextTransformer transformer = createStrictMock(ContextTransformer.class); + expect(transformer.transform(anyObject(Map.class))).andReturn(data1).times(1); + expect(transformer.transform(anyObject(Map.class))).andReturn(data2).times(1); + + replayAll(); + + ContainsPredicate predicate = new ContainsPredicate(transformer, "ONE"); + + Assert.assertTrue(predicate.evaluate(Collections.singletonMap("data", data1))); + Assert.assertFalse(predicate.evaluate(Collections.singletonMap("data", data2))); + + verifyAll(); + } + + @Test + public void testToMap() { + ContextTransformer transformer = createStrictMock(ContextTransformer.class); + expect(transformer.getKey()).andReturn("data").times(1); + + replayAll(); + + ContainsPredicate predicate = new ContainsPredicate(transformer, "ONE"); + Map<String, Object> actualMap = predicate.toMap(); + + verifyAll(); + + Map<String, Object> expectedMap = new HashMap<String, Object>(); + expectedMap.put("contains", new ArrayList<String>(Arrays.asList("data", "ONE"))); + + Assert.assertEquals(expectedMap, actualMap); + } + + @Test + public void testToJSON() { + ContextTransformer transformer = createStrictMock(ContextTransformer.class); + expect(transformer.getKey()).andReturn("data").times(1); + + replayAll(); + + ContainsPredicate predicate = new ContainsPredicate(transformer, "ONE"); + String actualJSON = predicate.toJSON(); + + verifyAll(); + + String expectedJSON = "{\"contains\":[\"data\",\"ONE\"]}"; + + Assert.assertEquals(expectedJSON, actualJSON); + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ambari/blob/2fcc9475/ambari-server/src/test/java/org/apache/ambari/server/collections/functors/ContextTransformerTest.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/collections/functors/ContextTransformerTest.java b/ambari-server/src/test/java/org/apache/ambari/server/collections/functors/ContextTransformerTest.java new file mode 100644 index 0000000..da77b35 --- /dev/null +++ b/ambari-server/src/test/java/org/apache/ambari/server/collections/functors/ContextTransformerTest.java @@ -0,0 +1,75 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ambari.server.collections.functors; + + +import junit.framework.Assert; +import org.easymock.EasyMockSupport; +import org.junit.Test; + +import java.util.HashMap; +import java.util.Map; + +public class ContextTransformerTest extends EasyMockSupport { + + @Test + public void testGetKey() { + ContextTransformer transformer = new ContextTransformer("key"); + Assert.assertEquals("key", transformer.getKey()); + } + + @Test + public void testTransformSimple() { + Map<String, Object> context = new HashMap<String, Object>(); + context.put("key", "value"); + context.put("key1", "value1"); + context.put("key2", "value2"); + + ContextTransformer transformer = new ContextTransformer("key"); + Assert.assertEquals("value", transformer.transform(context)); + } + + @Test + public void testTransformTree() { + Map<String, Object> serviceSite = new HashMap<String, Object>(); + serviceSite.put("property", "service-site-property"); + + Map<String, Object> configurations = new HashMap<String, Object>(); + configurations.put("service-site", serviceSite); + configurations.put("property", "configuration-property"); + + Map<String, Object> context = new HashMap<String, Object>(); + context.put("configurations", configurations); + context.put("property", "context-property"); + + ContextTransformer transformer; + + // Without leading "/" + transformer = new ContextTransformer("configurations/service-site/property"); + Assert.assertEquals("service-site-property", transformer.transform(context)); + + // With leading "/" + transformer = new ContextTransformer("/configurations/service-site/property"); + Assert.assertEquals("service-site-property", transformer.transform(context)); + + // Get map of properties + transformer = new ContextTransformer("/configurations/service-site"); + Assert.assertEquals(serviceSite, transformer.transform(context)); + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ambari/blob/2fcc9475/ambari-server/src/test/java/org/apache/ambari/server/collections/functors/EqualsPredicateTest.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/collections/functors/EqualsPredicateTest.java b/ambari-server/src/test/java/org/apache/ambari/server/collections/functors/EqualsPredicateTest.java new file mode 100644 index 0000000..0ea4454 --- /dev/null +++ b/ambari-server/src/test/java/org/apache/ambari/server/collections/functors/EqualsPredicateTest.java @@ -0,0 +1,89 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ambari.server.collections.functors; + +import org.easymock.EasyMockSupport; +import org.junit.Assert; +import org.junit.Test; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + +import static org.easymock.EasyMock.anyObject; +import static org.easymock.EasyMock.expect; + +public class EqualsPredicateTest extends EasyMockSupport { + + @Test + public void testEvaluate() { + String data1 = "value1"; + String data2 = "value2"; + + ContextTransformer transformer = createStrictMock(ContextTransformer.class); + expect(transformer.transform(anyObject(Map.class))).andReturn(data1).times(1); + expect(transformer.transform(anyObject(Map.class))).andReturn(data2).times(1); + + replayAll(); + + EqualsPredicate predicate = new EqualsPredicate(transformer, "value1"); + + Assert.assertTrue(predicate.evaluate(Collections.singletonMap("data", data1))); + Assert.assertFalse(predicate.evaluate(Collections.singletonMap("data", data2))); + + verifyAll(); + } + + @Test + public void testToMap() { + ContextTransformer transformer = createStrictMock(ContextTransformer.class); + expect(transformer.getKey()).andReturn("data").times(1); + + replayAll(); + + EqualsPredicate predicate = new EqualsPredicate(transformer, "value"); + Map<String, Object> actualMap = predicate.toMap(); + + verifyAll(); + + Map<String, Object> expectedMap = new HashMap<String, Object>(); + expectedMap.put("equals", new ArrayList<String>(Arrays.asList("data", "value"))); + + Assert.assertEquals(expectedMap, actualMap); + } + + @Test + public void testToJSON() { + ContextTransformer transformer = createStrictMock(ContextTransformer.class); + expect(transformer.getKey()).andReturn("data").times(1); + + replayAll(); + + EqualsPredicate predicate = new EqualsPredicate(transformer, "value"); + String actualJSON = predicate.toJSON(); + + verifyAll(); + + String expectedJSON = "{\"equals\":[\"data\",\"value\"]}"; + + Assert.assertEquals(expectedJSON, actualJSON); + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ambari/blob/2fcc9475/ambari-server/src/test/java/org/apache/ambari/server/collections/functors/NotPredicateTest.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/collections/functors/NotPredicateTest.java b/ambari-server/src/test/java/org/apache/ambari/server/collections/functors/NotPredicateTest.java new file mode 100644 index 0000000..f0b8ae3 --- /dev/null +++ b/ambari-server/src/test/java/org/apache/ambari/server/collections/functors/NotPredicateTest.java @@ -0,0 +1,89 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ambari.server.collections.functors; + +import org.apache.ambari.server.collections.Predicate; +import org.easymock.EasyMockSupport; +import org.junit.Assert; +import org.junit.Test; + +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + +import static org.easymock.EasyMock.expect; + +public class NotPredicateTest extends EasyMockSupport { + + @Test + public void testEvaluate() { + Predicate mockPredicate = createStrictMock(Predicate.class); + expect(mockPredicate.evaluate("context")).andReturn(true).times(1); + expect(mockPredicate.evaluate("context")).andReturn(false).times(1); + + replayAll(); + + NotPredicate predicate = new NotPredicate(mockPredicate); + + // Try with true + Assert.assertFalse(predicate.evaluate("context")); + + // Try with false + Assert.assertTrue(predicate.evaluate("context")); + + verifyAll(); + + Assert.assertArrayEquals(new Predicate[]{mockPredicate}, predicate.getPredicates()); + } + + @Test + public void testToMap() { + Predicate mockPredicate = createStrictMock(Predicate.class); + expect(mockPredicate.toMap()).andReturn(Collections.<String, Object>singletonMap("nop", "foo")).times(1); + + replayAll(); + + NotPredicate predicate = new NotPredicate(mockPredicate); + Map<String, Object> actualMap = predicate.toMap(); + + verifyAll(); + + Map<String, Object> expectedMap = new HashMap<String, Object>(); + expectedMap.put("not", Collections.<String, Object>singletonMap("nop", "foo")); + + Assert.assertEquals(expectedMap, actualMap); + } + + @Test + public void testToJSON() { + Predicate mockPredicate = createStrictMock(Predicate.class); + expect(mockPredicate.toMap()).andReturn(Collections.<String, Object>singletonMap("nop", "foo")).times(1); + + replayAll(); + + NotPredicate predicate = new NotPredicate(mockPredicate); + String actualJSON = predicate.toJSON(); + + verifyAll(); + + String expectedJSON = "{\"not\":{\"nop\":\"foo\"}}"; + + Assert.assertEquals(expectedJSON, actualJSON); + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ambari/blob/2fcc9475/ambari-server/src/test/java/org/apache/ambari/server/collections/functors/OrPredicateTest.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/collections/functors/OrPredicateTest.java b/ambari-server/src/test/java/org/apache/ambari/server/collections/functors/OrPredicateTest.java new file mode 100644 index 0000000..7e0bf1b --- /dev/null +++ b/ambari-server/src/test/java/org/apache/ambari/server/collections/functors/OrPredicateTest.java @@ -0,0 +1,107 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ambari.server.collections.functors; + +import org.apache.ambari.server.collections.Predicate; +import org.easymock.EasyMockSupport; +import org.junit.Assert; +import org.junit.Test; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + +import static org.easymock.EasyMock.expect; + +public class OrPredicateTest extends EasyMockSupport { + + @Test + public void testEvaluate() { + Predicate mockPredicate1 = createStrictMock(Predicate.class); + expect(mockPredicate1.evaluate("context")).andReturn(true).times(1); + expect(mockPredicate1.evaluate("context")).andReturn(false).times(1); + expect(mockPredicate1.evaluate("context")).andReturn(true).times(1); + + Predicate mockPredicate2 = createStrictMock(Predicate.class); + expect(mockPredicate2.evaluate("context")).andReturn(true).times(1); + + replayAll(); + + OrPredicate predicate = new OrPredicate(mockPredicate1, mockPredicate2); + + // Try with true and ???? (short circuited) + predicate.evaluate("context"); + + // Try with false and true + predicate.evaluate("context"); + + // Try with true and ???? (short circuited) + predicate.evaluate("context"); + + verifyAll(); + + Assert.assertArrayEquals(new Predicate[]{mockPredicate1, mockPredicate2}, predicate.getPredicates()); + } + + @Test + public void testToMap() { + Predicate mockPredicate1 = createStrictMock(Predicate.class); + expect(mockPredicate1.toMap()).andReturn(Collections.<String, Object>singletonMap("nop", "foo")).times(1); + + Predicate mockPredicate2 = createStrictMock(Predicate.class); + expect(mockPredicate2.toMap()).andReturn(Collections.<String, Object>singletonMap("nop", "baz")).times(1); + + replayAll(); + + OrPredicate predicate = new OrPredicate(mockPredicate1, mockPredicate2); + Map<String, Object> actualMap = predicate.toMap(); + + verifyAll(); + + Map<String, Object> expectedMap = new HashMap<String, Object>(); + expectedMap.put("or", new ArrayList<Map<String, Object>>( + Arrays.asList(Collections.<String, Object>singletonMap("nop", "foo"), + Collections.<String, Object>singletonMap("nop", "baz")) + )); + + Assert.assertEquals(expectedMap, actualMap); + } + + @Test + public void testToJSON() { + Predicate mockPredicate1 = createStrictMock(Predicate.class); + expect(mockPredicate1.toMap()).andReturn(Collections.<String, Object>singletonMap("nop", "foo")).times(1); + + Predicate mockPredicate2 = createStrictMock(Predicate.class); + expect(mockPredicate2.toMap()).andReturn(Collections.<String, Object>singletonMap("nop", "baz")).times(1); + + replayAll(); + + OrPredicate predicate = new OrPredicate(mockPredicate1, mockPredicate2); + String actualJSON = predicate.toJSON(); + + verifyAll(); + + String expectedJSON = "{\"or\":[{\"nop\":\"foo\"},{\"nop\":\"baz\"}]}"; + + Assert.assertEquals(expectedJSON, actualJSON); + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ambari/blob/2fcc9475/ambari-server/src/test/java/org/apache/ambari/server/controller/KerberosHelperTest.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/KerberosHelperTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/KerberosHelperTest.java index 5393fd6..c707a90 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/controller/KerberosHelperTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/KerberosHelperTest.java @@ -1952,19 +1952,19 @@ public class KerberosHelperTest extends EasyMockSupport { final KerberosIdentityDescriptor identityDescriptor1 = createMock(KerberosIdentityDescriptor.class); expect(identityDescriptor1.getPrincipalDescriptor()).andReturn(principalDescriptor1).times(1); -// expect(identityDescriptor1.getName()).andReturn("1").times(1); + expect(identityDescriptor1.shouldInclude(anyObject(Map.class))).andReturn(true).anyTimes(); final KerberosIdentityDescriptor identityDescriptor2 = createMock(KerberosIdentityDescriptor.class); expect(identityDescriptor2.getPrincipalDescriptor()).andReturn(principalDescriptor2).times(1); -// expect(identityDescriptor2.getName()).andReturn("2").times(1); + expect(identityDescriptor2.shouldInclude(anyObject(Map.class))).andReturn(true).anyTimes(); final KerberosIdentityDescriptor identityDescriptor3 = createMock(KerberosIdentityDescriptor.class); expect(identityDescriptor3.getPrincipalDescriptor()).andReturn(principalDescriptor3).times(1); -// expect(identityDescriptor3.getName()).andReturn("3").times(1); + expect(identityDescriptor3.shouldInclude(anyObject(Map.class))).andReturn(true).anyTimes(); final KerberosServiceDescriptor serviceDescriptor1 = createMock(KerberosServiceDescriptor.class); expect(serviceDescriptor1.getName()).andReturn("SERVICE1").times(2); - expect(serviceDescriptor1.getIdentities(true)).andReturn(Arrays.asList( + expect(serviceDescriptor1.getIdentities(eq(true), anyObject(Map.class))).andReturn(Arrays.asList( identityDescriptor1, identityDescriptor2, identityDescriptor3 @@ -1983,14 +1983,14 @@ public class KerberosHelperTest extends EasyMockSupport { final KerberosDescriptor kerberosDescriptor = createMock(KerberosDescriptor.class); expect(kerberosDescriptor.getProperty("additional_realms")).andReturn(null).times(1); - expect(kerberosDescriptor.getIdentities()).andReturn(null).times(1); + expect(kerberosDescriptor.getIdentities(eq(true), anyObject(Map.class))).andReturn(null).times(1); expect(kerberosDescriptor.getAuthToLocalProperties()).andReturn(null).times(1); expect(kerberosDescriptor.getServices()).andReturn(Collections.singletonMap("SERVICE1", serviceDescriptor1)).times(1); final Service service1 = createNiceMock(Service.class); final Cluster cluster = createNiceMock(Cluster.class); - expect(cluster.getServices()).andReturn(Collections.singletonMap("SERVICE1", service1)).times(1); + expect(cluster.getServices()).andReturn(Collections.singletonMap("SERVICE1", service1)).anyTimes(); Map<String, Map<String, String>> kerberosConfigurations = new HashMap<String, Map<String, String>>(); @@ -2253,7 +2253,7 @@ public class KerberosHelperTest extends EasyMockSupport { expect(kerberosDescriptor.getService("SERVICE2")).andReturn(serviceDescriptor2).atLeastOnce(); expect(kerberosDescriptor.getService("SERVICE3")).andReturn(serviceDescriptor3).atLeastOnce(); expect(kerberosDescriptor.getProperty("additional_realms")).andReturn(null).atLeastOnce(); - expect(kerberosDescriptor.getIdentities()).andReturn(null).atLeastOnce(); + expect(kerberosDescriptor.getIdentities(eq(true), anyObject(Map.class))).andReturn(null).atLeastOnce(); expect(kerberosDescriptor.getAuthToLocalProperties()).andReturn(Collections.singleton("core-site/auth.to.local")).atLeastOnce(); final ResourceProvider artifactResourceProvider = createMock(ArtifactResourceProvider.class); @@ -3820,30 +3820,36 @@ public class KerberosHelperTest extends EasyMockSupport { expect(identityDescriptor1.getName()).andReturn("identity1").anyTimes(); expect(identityDescriptor1.getPrincipalDescriptor()).andReturn(principalDescriptor1).anyTimes(); expect(identityDescriptor1.getKeytabDescriptor()).andReturn(keytabDescriptor1).anyTimes(); + expect(identityDescriptor1.shouldInclude(anyObject(Map.class))).andReturn(true).anyTimes(); + expect(identityDescriptor1.getWhen()).andReturn(null).anyTimes(); final KerberosIdentityDescriptor identityDescriptor2 = createMock(KerberosIdentityDescriptor.class); expect(identityDescriptor2.getName()).andReturn("identity2").anyTimes(); expect(identityDescriptor2.getPrincipalDescriptor()).andReturn(principalDescriptor2).anyTimes(); expect(identityDescriptor2.getKeytabDescriptor()).andReturn(keytabDescriptor2).anyTimes(); + expect(identityDescriptor2.shouldInclude(anyObject(Map.class))).andReturn(true).anyTimes(); + expect(identityDescriptor2.getWhen()).andReturn(null).anyTimes(); final KerberosIdentityDescriptor identityDescriptorService1 = createMock(KerberosIdentityDescriptor.class); expect(identityDescriptorService1.getName()).andReturn("identity3").anyTimes(); expect(identityDescriptorService1.getPrincipalDescriptor()).andReturn(principalDescriptorService1).anyTimes(); expect(identityDescriptorService1.getKeytabDescriptor()).andReturn(keytabDescriptorService1).anyTimes(); + expect(identityDescriptorService1.shouldInclude(anyObject(Map.class))).andReturn(true).anyTimes(); + expect(identityDescriptorService1.getWhen()).andReturn(null).anyTimes(); final KerberosComponentDescriptor componentDescriptor1 = createMock(KerberosComponentDescriptor.class); - expect(componentDescriptor1.getIdentities(true)).andReturn(Collections.singletonList(identityDescriptor1)).anyTimes(); + expect(componentDescriptor1.getIdentities(eq(true), anyObject(Map.class))).andReturn(Collections.singletonList(identityDescriptor1)).anyTimes(); final KerberosComponentDescriptor componentDescriptor2 = createMock(KerberosComponentDescriptor.class); - expect(componentDescriptor2.getIdentities(true)).andReturn(Collections.singletonList(identityDescriptor2)).anyTimes(); + expect(componentDescriptor2.getIdentities(eq(true), anyObject(Map.class))).andReturn(Collections.singletonList(identityDescriptor2)).anyTimes(); final KerberosServiceDescriptor serviceDescriptor1 = createMock(KerberosServiceDescriptor.class); expect(serviceDescriptor1.getComponent("COMPONENT1")).andReturn(componentDescriptor1).anyTimes(); - expect(serviceDescriptor1.getIdentities(true)).andReturn(Collections.singletonList(identityDescriptorService1)).anyTimes(); + expect(serviceDescriptor1.getIdentities(eq(true), anyObject(Map.class))).andReturn(Collections.singletonList(identityDescriptorService1)).anyTimes(); final KerberosServiceDescriptor serviceDescriptor2 = createMock(KerberosServiceDescriptor.class); expect(serviceDescriptor2.getComponent("COMPONENT2")).andReturn(componentDescriptor2).anyTimes(); - expect(serviceDescriptor2.getIdentities(true)).andReturn(null).anyTimes(); + expect(serviceDescriptor2.getIdentities(eq(true), anyObject(Map.class))).andReturn(null).anyTimes(); final KerberosDescriptor kerberosDescriptor = createMock(KerberosDescriptor.class); expect(kerberosDescriptor.getProperties()).andReturn(new HashMap<String, String>() { @@ -3934,7 +3940,7 @@ public class KerberosHelperTest extends EasyMockSupport { KerberosServiceDescriptor descriptor = createMock(KerberosServiceDescriptor.class); expect(descriptor.getName()).andReturn(serviceName).anyTimes(); expect(descriptor.getComponents()).andReturn(componentMap).anyTimes(); - expect(descriptor.getIdentities(true)).andReturn(identities).anyTimes(); + expect(descriptor.getIdentities(eq(true), anyObject(Map.class))).andReturn(identities).anyTimes(); expect(descriptor.getAuthToLocalProperties()).andReturn(null).anyTimes(); return descriptor; } @@ -3955,7 +3961,7 @@ public class KerberosHelperTest extends EasyMockSupport { throws AmbariException { KerberosComponentDescriptor descriptor = createMock(KerberosComponentDescriptor.class); expect(descriptor.getName()).andReturn(componentName).anyTimes(); - expect(descriptor.getIdentities(true)).andReturn(identities).anyTimes(); + expect(descriptor.getIdentities(eq(true), anyObject(Map.class))).andReturn(identities).anyTimes(); expect(descriptor.getConfigurations(true)).andReturn(configurations).anyTimes(); expect(descriptor.getAuthToLocalProperties()).andReturn(null).anyTimes(); return descriptor; http://git-wip-us.apache.org/repos/asf/ambari/blob/2fcc9475/ambari-server/src/test/java/org/apache/ambari/server/state/kerberos/KerberosDescriptorTest.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/state/kerberos/KerberosDescriptorTest.java b/ambari-server/src/test/java/org/apache/ambari/server/state/kerberos/KerberosDescriptorTest.java index d80d7cc..004cd66 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/state/kerberos/KerberosDescriptorTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/state/kerberos/KerberosDescriptorTest.java @@ -163,7 +163,7 @@ public class KerberosDescriptorTest { KerberosComponentDescriptor component = service.getComponent("A_DIFFERENT_COMPONENT_NAME"); Assert.assertNotNull(component); - List<KerberosIdentityDescriptor> resolvedIdentities = component.getIdentities(true); + List<KerberosIdentityDescriptor> resolvedIdentities = component.getIdentities(true, null); KerberosIdentityDescriptor resolvedIdentity = null; Assert.assertNotNull(resolvedIdentities); Assert.assertEquals(3, resolvedIdentities.size()); @@ -176,7 +176,7 @@ public class KerberosDescriptorTest { } Assert.assertNotNull(resolvedIdentity); - List<KerberosIdentityDescriptor> identities = component.getIdentities(false); + List<KerberosIdentityDescriptor> identities = component.getIdentities(false, null); Assert.assertNotNull(identities); Assert.assertEquals(3, identities.size()); http://git-wip-us.apache.org/repos/asf/ambari/blob/2fcc9475/ambari-server/src/test/java/org/apache/ambari/server/state/kerberos/KerberosIdentityDescriptorTest.java ---------------------------------------------------------------------- diff --git a/ambari-server/src/test/java/org/apache/ambari/server/state/kerberos/KerberosIdentityDescriptorTest.java b/ambari-server/src/test/java/org/apache/ambari/server/state/kerberos/KerberosIdentityDescriptorTest.java index 0ea7b26..79a861d 100644 --- a/ambari-server/src/test/java/org/apache/ambari/server/state/kerberos/KerberosIdentityDescriptorTest.java +++ b/ambari-server/src/test/java/org/apache/ambari/server/state/kerberos/KerberosIdentityDescriptorTest.java @@ -23,7 +23,9 @@ import junit.framework.Assert; import org.apache.ambari.server.AmbariException; import org.junit.Test; +import java.util.Arrays; import java.util.HashMap; +import java.util.HashSet; import java.util.Map; public class KerberosIdentityDescriptorTest { @@ -34,6 +36,8 @@ public class KerberosIdentityDescriptorTest { " \"principal\":" + KerberosPrincipalDescriptorTest.JSON_VALUE + "," + " \"keytab\":" + KerberosKeytabDescriptorTest.JSON_VALUE + + "," + + " \"when\": {\"contains\" : [\"services\", \"HIVE\"]}" + "}"; public static final Map<String, Object> MAP_VALUE = @@ -151,4 +155,17 @@ public class KerberosIdentityDescriptorTest { validateUpdatedData(identityDescriptor); } + + @Test + public void testShouldInclude() { + KerberosIdentityDescriptor identityDescriptor = createFromJSON(); + + Map<String, Object> context = new HashMap<String, Object>(); + + context.put("services", new HashSet<String>(Arrays.asList("HIVE", "HDFS", "ZOOKEEPER"))); + Assert.assertTrue(identityDescriptor.shouldInclude(context)); + + context.put("services", new HashSet<String>(Arrays.asList("NOT_HIVE", "HDFS", "ZOOKEEPER"))); + Assert.assertFalse(identityDescriptor.shouldInclude(context)); + } } \ No newline at end of file
