Merge "Remove auto generated rule to the drl"
authorJorge Hernandez <jh1730@att.com>
Tue, 6 Mar 2018 02:37:08 +0000 (02:37 +0000)
committerGerrit Code Review <gerrit@onap.org>
Tue, 6 Mar 2018 02:37:08 +0000 (02:37 +0000)
BRMSGateway/pom.xml
ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/components/MicroServicePolicyTest.java
ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/handler/DeleteHandlerTest.java [new file with mode: 0644]
ONAP-SDK-APP/pom.xml
ONAP-SDK-APP/src/test/java/org/onap/portalapp/login/LoginStrategyImplTest.java [new file with mode: 0644]
ONAP-SDK-APP/src/test/java/org/onap/portalapp/scheduler/RegisterTest.java [new file with mode: 0644]
ONAP-SDK-APP/src/test/java/org/onap/portalapp/scheduler/RegistryAdapterTest.java [new file with mode: 0644]
packages/docker/src/main/docker/Dockerfile
pom.xml

index 39e943b..0d9ebfb 100644 (file)
                        <artifactId>integrity-monitor</artifactId>
                        <version>${project.version}</version>
                </dependency>
+               <!--
+               CLM security fix - force use of commons-collections 3.2.2.
+               Remove this if a new version of nexus-rest-client-java is upgraded
+               to not use velocity (and then subsequently commons-collections v3.1 
+                -->
+               <dependency>
+                   <groupId>commons-collections</groupId>
+                   <artifactId>commons-collections</artifactId>
+                   <version>3.2.2</version>
+               </dependency>
                <dependency>
                        <groupId>org.sonatype.nexus</groupId>
                        <artifactId>nexus-rest-client-java</artifactId>
                        <version>2.3.1-01</version>
+                       <exclusions>
+                               <exclusion>
+                                       <groupId>commons-collections</groupId>
+                                       <artifactId>commons-collections</artifactId>
+                               </exclusion>
+                       </exclusions>
                </dependency>
                <dependency>
                        <groupId>com.thoughtworks.xstream</groupId>
index e99debd..fa4bd20 100644 (file)
  */
 package org.onap.policy.pap.xacml.rest.components;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.fail;
+import static org.mockito.Matchers.anyString;
+import static org.mockito.Mockito.when;
+import static org.mockito.Matchers.any;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.fail;
-import org.junit.Ignore;
+import org.junit.runner.RunWith;
+import org.mockito.Mockito;
+import org.onap.policy.pap.xacml.rest.daoimpl.CommonClassDaoImpl;
 import org.onap.policy.rest.adapter.PolicyRestAdapter;
-import com.att.research.xacml.api.pap.PAPException;
+import org.powermock.api.mockito.PowerMockito;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+import java.io.File;
+import java.util.Collections;
 
+@RunWith(PowerMockRunner.class)
+@PrepareForTest({MicroServiceConfigPolicy.class, CreateNewMicroServiceModel.class})
 public class MicroServicePolicyTest {
        @Rule
     public ExpectedException thrown = ExpectedException.none();
@@ -47,10 +60,13 @@ public class MicroServicePolicyTest {
                assertNull(policy.getCorrectPolicyDataObject());
        }
        
-       @Ignore
        @Test
-       public void testPrepareToSave() throws PAPException {
-               thrown.expect(NullPointerException.class);
+       public void testPrepareToSave() throws Exception {
+               // Need to mock internal dictionary retrieval
+               CommonClassDaoImpl impl = Mockito.mock(CommonClassDaoImpl.class);
+               PowerMockito.whenNew(CommonClassDaoImpl.class).withNoArguments().thenReturn(impl);
+               when(impl.getDataById(any(), anyString(), anyString())).thenReturn(null);
+               
                PolicyRestAdapter policyAdapter = new PolicyRestAdapter();
                MicroServiceConfigPolicy policy = new MicroServiceConfigPolicy(policyAdapter);
                policyAdapter.setHighestVersion(1);
@@ -59,6 +75,36 @@ public class MicroServicePolicyTest {
                policyAdapter.setJsonBody("{ \"version\": \"1.0\"}");
                policyAdapter.setServiceType("foo");
                policy.prepareToSave();
-               fail("Expected an exception");
+               assertEquals(policy.isPreparedToSave(), true);
+       }
+       
+       @Test
+       public void testCreateConstructor1() {
+               CreateNewMicroServiceModel model = new CreateNewMicroServiceModel(null, null, null, null);
+               assertNotNull(model);
+       }
+       
+       @Test
+       public void testCreateModel() throws Exception {
+               // Mock file retrieval
+               File testFile = new File("testFile");
+               File[] testList = new File[1];
+               testList[0] = testFile;
+               File impl = Mockito.mock(File.class);
+               PowerMockito.whenNew(File.class).withAnyArguments().thenReturn(impl);
+               when(impl.listFiles()).thenReturn(testList);
+               when(impl.isFile()).thenReturn(true);
+
+               // Mock internal dictionary retrieval
+               CommonClassDaoImpl daoImpl = Mockito.mock(CommonClassDaoImpl.class);
+               PowerMockito.whenNew(CommonClassDaoImpl.class).withNoArguments().thenReturn(daoImpl);
+               when(daoImpl.getDataById(any(), anyString(), anyString())).thenReturn(Collections.emptyList());
+
+               // Test create methods
+               String testFileName = "testFile.zip";
+               String testVal = "testVal";
+               CreateNewMicroServiceModel model = new CreateNewMicroServiceModel(testFileName, testVal, testVal, testVal, testVal);
+               model.addValuesToNewModel();
+               model.saveImportService();
        }
-}
\ No newline at end of file
+}
diff --git a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/handler/DeleteHandlerTest.java b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/handler/DeleteHandlerTest.java
new file mode 100644 (file)
index 0000000..9e9da17
--- /dev/null
@@ -0,0 +1,114 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP-PAP-REST
+ * ================================================================================
+ * Copyright (C) 2018 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.onap.policy.pap.xacml.rest.handler;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.fail;
+import static org.mockito.Mockito.when;
+import static org.mockito.Matchers.any;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mockito;
+import org.onap.policy.common.logging.ONAPLoggingContext;
+import org.onap.policy.pap.xacml.rest.XACMLPapServlet;
+import org.onap.policy.pap.xacml.rest.elk.client.PolicyElasticSearchController;
+import org.onap.policy.rest.jpa.PolicyEntity;
+import org.onap.policy.xacml.api.pap.PAPPolicyEngine;
+import org.onap.policy.xacml.std.pap.StdEngine;
+import org.powermock.api.mockito.PowerMockito;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+import org.powermock.modules.junit4.PowerMockRunner;
+import com.mockrunner.mock.web.MockHttpServletRequest;
+import com.mockrunner.mock.web.MockHttpServletResponse;
+import java.sql.Connection;
+import java.util.Collections;
+import java.util.List;
+import javax.persistence.EntityManager;
+
+@RunWith(PowerMockRunner.class)
+@PrepareForTest({DeleteHandler.class, XACMLPapServlet.class})
+public class DeleteHandlerTest {
+       @Test
+       public void testGets() {
+               DeleteHandler handler = new DeleteHandler();
+               assertNotNull(handler);
+               assertEquals(handler.preSafetyCheck(null), true);
+               assertNull(handler.getDeletedGroup());
+       }
+       
+       @Test
+       public void testGetInstance() {
+               DeleteHandler handler = DeleteHandler.getInstance();
+               assertNotNull(handler);
+       }
+       
+       @Test
+       public void testDeletes() throws Exception {
+               // Mock request
+               DeleteHandler handler = new DeleteHandler();
+               MockHttpServletRequest request = new MockHttpServletRequest();
+               request.setBodyContent("{\n\"PAPPolicyType\": \"StdPAPPolicy\"\n}\n");
+               
+               // Mock servlet
+               PAPPolicyEngine engine = Mockito.mock(StdEngine.class);
+               PowerMockito.mockStatic(XACMLPapServlet.class);
+               when(XACMLPapServlet.getPAPEngine()).thenReturn(engine);
+               when(engine.getGroup(any())).thenReturn(null);
+               
+               // Mock elastic search
+               PolicyElasticSearchController controller = Mockito.mock(PolicyElasticSearchController.class);
+               PowerMockito.whenNew(PolicyElasticSearchController.class).withNoArguments().thenReturn(controller);
+               
+               // Mock entity manager
+               EntityManager em = Mockito.mock(EntityManager.class);
+               
+               // Test deletion from PAP
+               MockHttpServletResponse response = new MockHttpServletResponse();
+               try {
+                       handler.doAPIDeleteFromPAP(request, response);
+               }
+               catch (Exception ex) {
+                       fail("Not expecting an exception: " + ex);
+               }
+               
+               // Test deletion from PDP
+               ONAPLoggingContext loggingContext = Mockito.mock(ONAPLoggingContext.class);
+               try {
+                       handler.doAPIDeleteFromPDP(request, response, loggingContext);
+               }
+               catch (Exception ex) {
+                       fail("Not expecting an exception: " + ex);
+               }
+               
+               // Test delete entity
+               PolicyEntity policyEntity = new PolicyEntity();
+               policyEntity.setPolicyName("testVal");
+               String result = DeleteHandler.deletePolicyEntityData(em, policyEntity);
+               assertEquals(result, "success");
+               
+               // Test check entity
+               Connection con = null;
+               List<?> peResult = Collections.emptyList();
+               assertEquals(DeleteHandler.checkPolicyGroupEntity(con, peResult), false);
+       }
+}
index c1ce21e..687e5b3 100644 (file)
                        <type>jar</type>
                </dependency>
                <!-- SDK components -->
+               <!--
+               CLM security fix - force use of commons-collections 3.2.2.
+               Remove this if a new version of epsdk-core is upgraded
+               to not use esapi (and then subsequently commons-collections v3.2
+                -->
+               <dependency>
+                   <groupId>commons-collections</groupId>
+                   <artifactId>commons-collections</artifactId>
+                   <version>3.2.2</version>
+               </dependency>
                <dependency>
                        <groupId>org.onap.portal.sdk</groupId>
                        <artifactId>epsdk-core</artifactId>
                                        <groupId>mysql</groupId>
                                        <artifactId>mysql-connector-java</artifactId>
                                </exclusion>
+                               <exclusion>
+                                       <groupId>commons-collections</groupId>
+                                       <artifactId>commons-collections</artifactId>
+                               </exclusion>
                        </exclusions>
                </dependency>
                <dependency>
diff --git a/ONAP-SDK-APP/src/test/java/org/onap/portalapp/login/LoginStrategyImplTest.java b/ONAP-SDK-APP/src/test/java/org/onap/portalapp/login/LoginStrategyImplTest.java
new file mode 100644 (file)
index 0000000..25b6779
--- /dev/null
@@ -0,0 +1,39 @@
+/*-
+ * ================================================================================
+ * ONAP Portal SDK
+ * ================================================================================
+ * Copyright (C) 2018 AT&T Intellectual Property
+ * ================================================================================
+ * 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.
+ * ================================================================================
+ */
+
+package org.onap.portalapp.login;
+
+import static org.junit.Assert.assertNull;
+import javax.servlet.http.Cookie;
+import org.junit.Test;
+import org.onap.portalsdk.core.onboarding.exception.PortalAPIException;
+import org.springframework.mock.web.MockHttpServletRequest;
+
+public class LoginStrategyImplTest {
+       @Test
+       public void testLoginStrategyImpl() throws PortalAPIException {
+               LoginStrategyImpl impl = new LoginStrategyImpl();
+               MockHttpServletRequest request = new MockHttpServletRequest();
+               Cookie cookie1 = new Cookie("EPService", "serviceName");
+               Cookie cookie2 = new Cookie("UserId", "userName");
+               request.setCookies(cookie1, cookie2);
+               assertNull(impl.getUserId(request));
+       }
+}
diff --git a/ONAP-SDK-APP/src/test/java/org/onap/portalapp/scheduler/RegisterTest.java b/ONAP-SDK-APP/src/test/java/org/onap/portalapp/scheduler/RegisterTest.java
new file mode 100644 (file)
index 0000000..ec7724c
--- /dev/null
@@ -0,0 +1,57 @@
+/*-
+ * ================================================================================
+ * ONAP Portal SDK
+ * ================================================================================
+ * Copyright (C) 2018 AT&T Intellectual Property
+ * ================================================================================
+ * 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.
+ * ================================================================================
+ */
+
+package org.onap.portalapp.scheduler;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+import java.util.ArrayList;
+import java.util.List;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.quartz.Trigger;
+import org.quartz.TriggerBuilder;
+
+public class RegisterTest {
+       @Rule 
+       public final ExpectedException thrown = ExpectedException.none();
+
+       @Test
+       public void testRegister() {
+               Register register = new Register();
+               TriggerBuilder<Trigger> triggerBuilder = TriggerBuilder.newTrigger();
+               Trigger trigger = triggerBuilder.build();
+               List<Trigger> triggers = new ArrayList<Trigger>();
+               triggers.add(trigger);
+               
+               register.setScheduleTriggers(triggers);
+               assertEquals(register.getScheduleTriggers(), triggers);
+               assertEquals(register.getTriggers().length, 1);
+       }
+       
+       @Test
+       public void testRegisterNegativeCase() {
+               thrown.expect(NullPointerException.class);
+               Register register = new Register();
+               register.registerTriggers();
+               fail("Expecting an exception.");
+       }
+}
diff --git a/ONAP-SDK-APP/src/test/java/org/onap/portalapp/scheduler/RegistryAdapterTest.java b/ONAP-SDK-APP/src/test/java/org/onap/portalapp/scheduler/RegistryAdapterTest.java
new file mode 100644 (file)
index 0000000..b49ad6a
--- /dev/null
@@ -0,0 +1,68 @@
+/*-
+ * ================================================================================
+ * ONAP Portal SDK
+ * ================================================================================
+ * Copyright (C) 2018 AT&T Intellectual Property
+ * ================================================================================
+ * 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.
+ * ================================================================================
+ */
+
+package org.onap.portalapp.scheduler;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.onap.portalsdk.core.scheduler.Registerable;
+import org.onap.portalsdk.workflow.services.WorkflowScheduleService;
+import org.springframework.scheduling.quartz.SchedulerFactoryBean;
+
+public class RegistryAdapterTest {
+       @Rule 
+       public final ExpectedException thrown = ExpectedException.none();
+
+       @Test
+       public void testRegistryAdapter() {
+               RegistryAdapter adapter = new RegistryAdapter();
+               SchedulerFactoryBean schedulerBean = new SchedulerFactoryBean();
+               Registerable registry = null;
+               WorkflowScheduleService workflowScheduleService = null;
+
+               adapter.setSchedulerBean(schedulerBean);
+               assertEquals(adapter.getSchedulerBean(), schedulerBean);
+               adapter.setRegistry(registry);
+               assertEquals(adapter.getRegistry(), registry);
+               adapter.setWorkflowScheduleService(workflowScheduleService);
+               assertEquals(adapter.getWorkflowScheduleService(), workflowScheduleService);
+       }
+       
+       @Test
+       public void testRegistryAdapterNegCase1() {
+               thrown.expect(NullPointerException.class);
+
+               RegistryAdapter adapter = new RegistryAdapter();
+               adapter.getTriggers();
+               fail("Expecting an exception.");
+       }
+       
+       @Test
+       public void testRegistryAdapterNegCase2() {
+               thrown.expect(NullPointerException.class);
+
+               RegistryAdapter adapter = new RegistryAdapter();
+               adapter.addCoreTriggers();
+               fail("Expecting an exception.");
+       }
+}
index fe56808..b0e8205 100644 (file)
@@ -1,4 +1,33 @@
-FROM onap/policy/policy-base
+FROM ubuntu:14.04
+
+ARG HTTP_PROXY=${HTTP_PROXY}
+ARG HTTPS_PROXY=${HTTPS_PROXY}
+
+ENV http_proxy $HTTP_PROXY
+ENV https_proxy $HTTPS_PROXY
+
+RUN \
+        apt-get clean && \
+        apt-get update && \
+        apt-get install -y zip unzip curl wget ssh telnet maven && \
+        apt-get install -y software-properties-common && \
+        apt-get install -y jq httpie && \
+        apt-get install -y python-pip && \
+        add-apt-repository ppa:openjdk-r/ppa && \
+        apt-get clean && \
+        apt-get update && \
+        apt-get install -y openjdk-8-jdk
+
+RUN useradd --create-home --shell /bin/bash policy
+
+# install MariaDB client
+RUN \
+    apt-get install -y apt-transport-https && \
+        apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xcbcb082a1bb943db && \
+        add-apt-repository 'deb [arch=amd64,i386,ppc64el] http://ftp.osuosl.org/pub/mariadb/repo/10.0/ubuntu trusty main' && \
+        apt-get clean && \
+        apt-get update && \
+        apt-get install -y mariadb-client
 
 RUN mkdir -p /opt/app/policy /tmp/policy-install && chown policy /opt/app/policy /tmp/policy-install
 
diff --git a/pom.xml b/pom.xml
index eba1c04..5338855 100644 (file)
--- a/pom.xml
+++ b/pom.xml
@@ -67,7 +67,7 @@
 
                <!-- Project common dependency versions -->
                <jetty.plugin.version>9.2.3.v20140905</jetty.plugin.version>
-               <dmaap.version>1.0.0</dmaap.version>
+               <dmaap.version>1.1.3-SNAPSHOT</dmaap.version>
                <httpclient.version>4.5.5</httpclient.version>
                <jackson.version>2.9.4</jackson.version>
                <commons.fileupload.version>1.3.3</commons.fileupload.version>
                </site>
        </distributionManagement>
 
-        <repositories>
-                <!-- LF repositories -->
-                <repository>
-                        <id>ecomp-releases</id>
-                        <name>Release Repository</name>
-                        <url>${nexusproxy}/content/repositories/releases/</url>
-                </repository>
-                <repository>
-                        <id>ecomp-staging</id>
-                        <name>Staging Repository</name>
-                        <url>${nexusproxy}/content/repositories/staging/</url>
-                </repository>
-                <repository>
-                        <id>ecomp-snapshots</id>
-                        <name>Snapshots Repository</name>
-                        <url>${nexusproxy}/content/repositories/snapshots/</url>
-                </repository>
-                <repository>
-                        <id>ecomp-public</id>
-                        <name>Public Repository</name>
-                        <url>${nexusproxy}/content/repositories/public/</url>
-                </repository>
-                <!-- LF repositories END-->
-        </repositories>
-
        <reporting>
          <plugins>
            <plugin>