From 34f82fce815c23f0ae3df3643ee262af396c236c Mon Sep 17 00:00:00 2001 From: Venkata Harish K Kajur Date: Tue, 19 Sep 2017 02:18:52 -0400 Subject: Add ability to apply configurations to vnf Issue-ID: AAI-326 Change-Id: Id5480d020f66a6b8d83310d85eb0678f6b504e7a Signed-off-by: Venkata Harish K Kajur --- .../java/org/openecomp/aai/logging/CNNameTest.java | 137 +++++++++++++++++++++ .../aai/logging/CustomLogPatternLayoutTest.java | 51 ++++++++ .../openecomp/aai/logging/DME2RestFlagTest.java | 82 ++++++++++++ .../java/org/openecomp/aai/util/CNNameTest.java | 136 -------------------- .../aai/util/CustomLogPatternLayoutTest.java | 51 -------- 5 files changed, 270 insertions(+), 187 deletions(-) create mode 100644 aai-core/src/test/java/org/openecomp/aai/logging/CNNameTest.java create mode 100644 aai-core/src/test/java/org/openecomp/aai/logging/CustomLogPatternLayoutTest.java create mode 100644 aai-core/src/test/java/org/openecomp/aai/logging/DME2RestFlagTest.java delete mode 100644 aai-core/src/test/java/org/openecomp/aai/util/CNNameTest.java delete mode 100644 aai-core/src/test/java/org/openecomp/aai/util/CustomLogPatternLayoutTest.java (limited to 'aai-core/src/test') diff --git a/aai-core/src/test/java/org/openecomp/aai/logging/CNNameTest.java b/aai-core/src/test/java/org/openecomp/aai/logging/CNNameTest.java new file mode 100644 index 00000000..b4705030 --- /dev/null +++ b/aai-core/src/test/java/org/openecomp/aai/logging/CNNameTest.java @@ -0,0 +1,137 @@ +/*- + * ============LICENSE_START======================================================= + * org.openecomp.aai + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.aai.logging; + +import ch.qos.logback.access.spi.IAccessEvent; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mockito; +import org.openecomp.aai.logging.CNName; +import org.openecomp.aai.serialization.queryformats.QueryFormatTestHelper; +import org.openecomp.aai.util.AAIConstants; +import org.powermock.core.classloader.annotations.PowerMockIgnore; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.powermock.modules.agent.PowerMockAgent; + +import javax.security.auth.x500.X500Principal; +import javax.servlet.http.HttpServletRequest; +import java.security.cert.X509Certificate; + +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.when; + +@PowerMockIgnore("javax.security.auth.x500.X500Principal") +@PrepareForTest({IAccessEvent.class, HttpServletRequest.class, X509Certificate.class}) +public class CNNameTest { + + static { + PowerMockAgent.initializeIfNeeded(); + } + + + IAccessEvent mockAccEvent; + HttpServletRequest mockHttpServletRequest; + CNName cnname; + X509Certificate cert; + + /** + * Initialize. + */ + @Before + public void initialize() throws Exception { + System.setProperty("AJSC_HOME", "."); + System.setProperty("BUNDLECONFIG_DIR", "src/test/resources/bundleconfig-local"); + QueryFormatTestHelper.setFinalStatic(AAIConstants.class.getField("AAI_HOME_ETC_OXM"), "src/test/resources/bundleconfig-local/etc/oxm/"); + mockAccEvent = Mockito.mock(IAccessEvent.class); + mockHttpServletRequest = Mockito.mock(HttpServletRequest.class); + cert = Mockito.mock(X509Certificate.class); + } + + + /** + * Test 'convert' when there is no AccessConverter. + */ + @Test + public void testConvert_withoutAccessConverter(){ + cnname = getTestObj(false); + assertTrue("Conversion failed with no AccessConverter", "INACTIVE_HEADER_CONV".equals(cnname.convert(mockAccEvent))); + } + + /** + * Test 'convert' with no CipherSuite. + */ + @Test + public void testConvert_withNullCipherSuite(){ + setupForCipherSuite(null); + assertTrue("Conversion failed for a null CipherSuite", "-".equals(cnname.convert(mockAccEvent))); + } + + + /** + * Test 'convert' with a non-null CipherSuite. + */ + @Test + public void testConvert_withNotNullCipherSuite(){ + + setupForCipherSuite("StrRepOfAValidSuite"); + + final X500Principal principal = new X500Principal("CN=AAI, OU=DOX, O=BWS, C=CA"); + + Mockito.when(cert.getSubjectX500Principal()).thenReturn(principal); + + final X509Certificate[] certChain = {cert}; + + when(mockHttpServletRequest.getAttribute("javax.servlet.request.X509Certificate")).thenReturn(certChain); + + assertTrue("Conversion failed for a valid CipherSuite", principal.toString().equals(cnname.convert(mockAccEvent))); + } + + + /** + * Helper method to mock IAccessEvent and HttpServletRequest. + * + * @param suite CipherSuite to be used in current test + */ + private void setupForCipherSuite(String suite){ + cnname = getTestObj(true); + when(mockAccEvent.getRequest()).thenReturn(mockHttpServletRequest); + when(mockHttpServletRequest.getAttribute("javax.servlet.request.cipher_suite")).thenReturn(suite); + } + + + /** + * Helper method to create a CNName object with overridden 'start status' . + * + * @param instanceStarted Start status to be used + * @return CNName object to test + */ + private CNName getTestObj(final boolean instanceStarted){ + return new CNName(){ + @Override + public boolean isStarted(){ + return instanceStarted; + } + }; + } +} + + + diff --git a/aai-core/src/test/java/org/openecomp/aai/logging/CustomLogPatternLayoutTest.java b/aai-core/src/test/java/org/openecomp/aai/logging/CustomLogPatternLayoutTest.java new file mode 100644 index 00000000..3e79646b --- /dev/null +++ b/aai-core/src/test/java/org/openecomp/aai/logging/CustomLogPatternLayoutTest.java @@ -0,0 +1,51 @@ +/*- + * ============LICENSE_START======================================================= + * org.openecomp.aai + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.aai.logging; + +import org.junit.Test; +import org.openecomp.aai.logging.CNName; +import org.openecomp.aai.logging.CustomLogPatternLayout; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +public class CustomLogPatternLayoutTest { + + /** + * Test null when defaultConverterMap doesn't have corresponding entry. + */ + @Test + public void testNull(){ + String s = CustomLogPatternLayout.defaultConverterMap.get("z"); + assertFalse("Entry not found for key 'z'", CNName.class.getName().equals(s)); + } + + /** + * Test defaultConverterMap when valid entry exists. + */ + @Test + public void testEntryFor_Z(){ + CustomLogPatternLayout layout = new CustomLogPatternLayout(); + String s = CustomLogPatternLayout.defaultConverterMap.get("z"); + assertTrue("Entry not found for key 'z'", CNName.class.getName().equals(s)); + } + +} diff --git a/aai-core/src/test/java/org/openecomp/aai/logging/DME2RestFlagTest.java b/aai-core/src/test/java/org/openecomp/aai/logging/DME2RestFlagTest.java new file mode 100644 index 00000000..b20f1328 --- /dev/null +++ b/aai-core/src/test/java/org/openecomp/aai/logging/DME2RestFlagTest.java @@ -0,0 +1,82 @@ +/*- + * ============LICENSE_START======================================================= + * org.openecomp.aai + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed 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. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.aai.logging; +import static org.junit.Assert.*; +import static org.mockito.Mockito.*; +import ch.qos.logback.access.spi.IAccessEvent; +import org.junit.*; + + +public class DME2RestFlagTest { + + IAccessEvent mockAccEvent; + DME2RestFlag _DME2RestFlag; + + String[] temp = new String[4]; + + + @Before + public void setUp() throws Exception { + + mockAccEvent = mock(IAccessEvent.class); + _DME2RestFlag= spy(DME2RestFlag.class); + + } + private DME2RestFlag getTestObj(final boolean instanceStarted){ + return new DME2RestFlag(){ + @Override + public + boolean isStarted(){ + return instanceStarted; + } + }; + } + + @Test + public void convertTestAllValid(){ + temp[0]= "temp1"; + temp[1] = "-"; + when(mockAccEvent.getRequestParameter("envContext")).thenReturn(temp); + when(mockAccEvent.getRequestParameter("routeOffer")).thenReturn(temp); + when(mockAccEvent.getRequestParameter("version")).thenReturn(temp); + _DME2RestFlag = getTestObj(true); + assertEquals(_DME2RestFlag.convert(mockAccEvent),"DME2"); + } + + @Test + public void convertMissingRouteTest(){ + temp[0]= ""; + temp[1] = "-"; + when(mockAccEvent.getRequestParameter("envContext")).thenReturn(temp); + when(mockAccEvent.getRequestParameter("routeOffer")).thenReturn(temp); + when(mockAccEvent.getRequestParameter("version")).thenReturn(temp); + _DME2RestFlag = getTestObj(true); + assertEquals(_DME2RestFlag.convert(mockAccEvent),"REST"); + } + + @Test + public void convertIsStartedFalseTest(){ + _DME2RestFlag = getTestObj(false); + assertEquals(_DME2RestFlag.convert(mockAccEvent),"INACTIVE_HEADER_CONV"); + } + + +} diff --git a/aai-core/src/test/java/org/openecomp/aai/util/CNNameTest.java b/aai-core/src/test/java/org/openecomp/aai/util/CNNameTest.java deleted file mode 100644 index f5b67233..00000000 --- a/aai-core/src/test/java/org/openecomp/aai/util/CNNameTest.java +++ /dev/null @@ -1,136 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * org.openecomp.aai - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed 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. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.aai.util; - -import ch.qos.logback.access.spi.IAccessEvent; -import org.junit.Before; -import org.junit.Test; -import org.mockito.Mockito; -import org.openecomp.aai.logging.CNName; -import org.openecomp.aai.serialization.queryformats.QueryFormatTestHelper; -import org.powermock.core.classloader.annotations.PowerMockIgnore; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.agent.PowerMockAgent; - -import javax.security.auth.x500.X500Principal; -import javax.servlet.http.HttpServletRequest; -import java.security.cert.X509Certificate; - -import static org.junit.Assert.assertTrue; -import static org.mockito.Mockito.when; - -@PowerMockIgnore("javax.security.auth.x500.X500Principal") -@PrepareForTest({IAccessEvent.class, HttpServletRequest.class, X509Certificate.class}) -public class CNNameTest { - - static { - PowerMockAgent.initializeIfNeeded(); - } - - - IAccessEvent mockAccEvent; - HttpServletRequest mockHttpServletRequest; - CNName cnname; - X509Certificate cert; - - /** - * Initialize. - */ - @Before - public void initialize() throws Exception { - System.setProperty("AJSC_HOME", "."); - System.setProperty("BUNDLECONFIG_DIR", "src/test/resources/bundleconfig-local"); - QueryFormatTestHelper.setFinalStatic(AAIConstants.class.getField("AAI_HOME_ETC_OXM"), "src/test/resources/bundleconfig-local/etc/oxm/"); - mockAccEvent = Mockito.mock(IAccessEvent.class); - mockHttpServletRequest = Mockito.mock(HttpServletRequest.class); - cert = Mockito.mock(X509Certificate.class); - } - - - /** - * Test 'convert' when there is no AccessConverter. - */ - @Test - public void testConvert_withoutAccessConverter(){ - cnname = getTestObj(false); - assertTrue("Conversion failed with no AccessConverter", "INACTIVE_HEADER_CONV".equals(cnname.convert(mockAccEvent))); - } - - /** - * Test 'convert' with no CipherSuite. - */ - @Test - public void testConvert_withNullCipherSuite(){ - setupForCipherSuite(null); - assertTrue("Conversion failed for a null CipherSuite", "-".equals(cnname.convert(mockAccEvent))); - } - - - /** - * Test 'convert' with a non-null CipherSuite. - */ - @Test - public void testConvert_withNotNullCipherSuite(){ - - setupForCipherSuite("StrRepOfAValidSuite"); - - final X500Principal principal = new X500Principal("CN=AAI, OU=DOX, O=BWS, C=CA"); - - Mockito.when(cert.getSubjectX500Principal()).thenReturn(principal); - - final X509Certificate[] certChain = {cert}; - - when(mockHttpServletRequest.getAttribute("javax.servlet.request.X509Certificate")).thenReturn(certChain); - - assertTrue("Conversion failed for a valid CipherSuite", principal.toString().equals(cnname.convert(mockAccEvent))); - } - - - /** - * Helper method to mock IAccessEvent and HttpServletRequest. - * - * @param suite CipherSuite to be used in current test - */ - private void setupForCipherSuite(String suite){ - cnname = getTestObj(true); - when(mockAccEvent.getRequest()).thenReturn(mockHttpServletRequest); - when(mockHttpServletRequest.getAttribute("javax.servlet.request.cipher_suite")).thenReturn(suite); - } - - - /** - * Helper method to create a CNName object with overridden 'start status' . - * - * @param instanceStarted Start status to be used - * @return CNName object to test - */ - private CNName getTestObj(final boolean instanceStarted){ - return new CNName(){ - @Override - public boolean isStarted(){ - return instanceStarted; - } - }; - } -} - - - diff --git a/aai-core/src/test/java/org/openecomp/aai/util/CustomLogPatternLayoutTest.java b/aai-core/src/test/java/org/openecomp/aai/util/CustomLogPatternLayoutTest.java deleted file mode 100644 index 31a7b5e4..00000000 --- a/aai-core/src/test/java/org/openecomp/aai/util/CustomLogPatternLayoutTest.java +++ /dev/null @@ -1,51 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * org.openecomp.aai - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Licensed 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. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.aai.util; - -import org.junit.Test; -import org.openecomp.aai.logging.CNName; -import org.openecomp.aai.logging.CustomLogPatternLayout; - -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -public class CustomLogPatternLayoutTest { - - /** - * Test null when defaultConverterMap doesn't have corresponding entry. - */ - @Test - public void testNull(){ - String s = CustomLogPatternLayout.defaultConverterMap.get("z"); - assertFalse("Entry not found for key 'z'", CNName.class.getName().equals(s)); - } - - /** - * Test defaultConverterMap when valid entry exists. - */ - @Test - public void testEntryFor_Z(){ - CustomLogPatternLayout layout = new CustomLogPatternLayout(); - String s = CustomLogPatternLayout.defaultConverterMap.get("z"); - assertTrue("Entry not found for key 'z'", CNName.class.getName().equals(s)); - } - -} -- cgit 1.2.3-korg