package org.onap.policy.admin;
+import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
import static org.junit.Assert.fail;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import org.junit.Test;
import org.mockito.Mockito;
import org.onap.policy.controller.CreateFirewallController;
+import org.onap.policy.controller.PolicyController;
import org.onap.policy.rest.dao.CommonClassDao;
import org.onap.policy.rest.jpa.ActionList;
import org.onap.policy.rest.jpa.AddressGroup;
-import org.onap.policy.rest.jpa.FWTagPicker;
+import org.onap.policy.rest.jpa.FwTagPicker;
import org.onap.policy.rest.jpa.GroupServiceList;
import org.onap.policy.rest.jpa.PrefixList;
import org.onap.policy.rest.jpa.SecurityZone;
private List<Object> tagListData;
private List<Object> termListData;
+ /**
+ * Before.
+ *
+ * @throws Exception exception
+ */
@Before
public void setUp() throws Exception {
commonClassDao = mock(CommonClassDao.class);
- HttpSession mockSession = mock(HttpSession.class);
+ final HttpSession mockSession = mock(HttpSession.class);
request = mock(HttpServletRequest.class);
response = new MockHttpServletResponse();
User user = new User();
ServiceList serviceList = new ServiceList();
serviceList.setServiceName("Test");
serviceList.setServiceType("SERVICE");
- serviceList.setServiceTransProtocol("Test");
+ serviceList.setServiceTransportProtocol("Test");
serviceList.setServiceAppProtocol("Test");
serviceList.setServicePorts("8080");
serviceListData.add(serviceList);
when(commonClassDao.getData(GroupServiceList.class)).thenReturn(serviceGroupData);
tagListData = new ArrayList<>();
- FWTagPicker fwPicker = new FWTagPicker();
+ FwTagPicker fwPicker = new FwTagPicker();
fwPicker.setTagPickerName("Test");
fwPicker.setTagValues("Test:8080");
tagListData.add(fwPicker);
- when(commonClassDao.getData(FWTagPicker.class)).thenReturn(tagListData);
+ when(commonClassDao.getData(FwTagPicker.class)).thenReturn(tagListData);
termListData = new ArrayList<>();
TermList termList = new TermList();
termList.setTermName("Test");
- termList.setFromZones("Test");
- termList.setToZones("Test");
- termList.setSrcIPList("Test");
- termList.setDestIPList("Test");
+ termList.setFromZone("Test");
+ termList.setToZone("Test");
+ termList.setSrcIpList("Test");
+ termList.setDestIpList("Test");
termList.setSrcPortList("Test");
termList.setDestPortList("Test");
termList.setAction("Test");
@Test
public final void testPolicyCreationController() {
+ assertNull(PolicyRestController.getCommonClassDao());
+ PolicyRestController.setCommonClassDao(commonClassDao);
+ assertNotNull(PolicyRestController.getCommonClassDao());
+
PolicyRestController controller = new PolicyRestController();
BufferedReader reader = new BufferedReader(new StringReader(clRequestString));
try {
}
PolicyRestController controller1 = new PolicyRestController();
CreateFirewallController.setCommonClassDao(commonClassDao);
+ assertNotNull(CreateFirewallController.getCommonClassDao());
BufferedReader reader1 = new BufferedReader(new StringReader(fwRequestString));
try {
Mockito.when(request.getReader()).thenReturn(reader1);
}
}
+ @Test
+ public final void testSearchPolicy() throws IOException {
+ PolicyController.setjUnit(true);
+ PolicyController.setPapUrl("http://localhost:8070/pap/");
+ PolicyRestController controller = new PolicyRestController();
+ BufferedReader reader = new BufferedReader(new StringReader("{\"foo\":\"bar\"}"));
+ Mockito.when(request.getReader()).thenReturn(reader);
+ Mockito.when(request.getRequestURI()).thenReturn("/pap/foo/");
+ assertThatExceptionOfType(NullPointerException.class).isThrownBy(() ->
+ controller.searchPolicy(request, response));
+ }
+
+ @Test
+ public final void testSearchDictionaryController() throws IOException {
+ PolicyRestController controller = new PolicyRestController();
+ BufferedReader reader = new BufferedReader(new StringReader("{\"foo\":\"bar\"}"));
+ Mockito.when(request.getReader()).thenReturn(reader);
+ Mockito.when(request.getRequestURI()).thenReturn("/pap/foo/");
+ assertNull(controller.searchDictionaryController(request, response));
+ }
+
@Test
public final void testDeleteElasticData() {
PolicyRestController controller = new PolicyRestController();
fail();
}
}
+
+ @Test
+ public final void testNotifyOtherPaps() {
+ PolicyRestController controller = new PolicyRestController();
+ String strReturn = controller.notifyOtherPapsToUpdateConfigurations("mode", "newName", "oldName");
+ assertNull(strReturn);
+ }
}