MariaDB Connector and Sonar Scans; clean nl
[portal.git] / ecomp-portal-BE-common / src / test / java / org / openecomp / portalapp / portal / controller / ManifestControllerTest.java
diff --git a/ecomp-portal-BE-common/src/test/java/org/openecomp/portalapp/portal/controller/ManifestControllerTest.java b/ecomp-portal-BE-common/src/test/java/org/openecomp/portalapp/portal/controller/ManifestControllerTest.java
new file mode 100644 (file)
index 0000000..c7a870c
--- /dev/null
@@ -0,0 +1,56 @@
+package org.openecomp.portalapp.portal.controller;
+
+import static org.junit.Assert.assertTrue;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.jar.Attributes;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
+import org.openecomp.portalapp.portal.framework.MockitoTestSuite;
+import org.openecomp.portalapp.portal.controller.ManifestController;
+import org.openecomp.portalapp.portal.service.ManifestService;
+import org.openecomp.portalapp.portal.service.ManifestServiceImpl;
+
+public class ManifestControllerTest extends MockitoTestSuite{
+
+       
+       @Mock
+       ManifestService manifestService = new ManifestServiceImpl();
+       
+       @InjectMocks
+       ManifestController  manifestController = new  ManifestController();
+       
+       @Before
+       public void setup() {
+               MockitoAnnotations.initMocks(this);
+       }
+       NullPointerException nullPointerException = new NullPointerException();
+       
+       @Test
+       public void getManifestTest() throws IOException
+       {
+               Map<String, Object> expectedResponse = new HashMap<String, Object>();
+               Attributes attributes  = new Attributes();
+               expectedResponse.put("test", attributes);
+               Mockito.when(manifestService.getWebappManifest()).thenReturn(attributes);
+               Map<String, Object> actualResponse = manifestController.getManifest(mockedRequest);
+               assertTrue((actualResponse.keySet().toArray().length) == 1);
+               
+       }
+       
+       @Test
+       public void getManifestExceptionTest() throws IOException
+       {
+               Mockito.when(manifestService.getWebappManifest()).thenThrow(nullPointerException);
+               Map<String, Object> actualResponse = manifestController.getManifest(mockedRequest);
+               assertTrue((actualResponse.keySet().toArray().length) == 1);
+               assertTrue(actualResponse.get("error").equals("failed to get manifest: java.lang.NullPointerException"));
+       }
+}