diff options
Diffstat (limited to 'src/test')
3 files changed, 192 insertions, 2 deletions
diff --git a/src/test/java/org/onap/music/exceptions/MusicExceptionMapperTest.java b/src/test/java/org/onap/music/exceptions/MusicExceptionMapperTest.java new file mode 100644 index 00000000..bbfa9832 --- /dev/null +++ b/src/test/java/org/onap/music/exceptions/MusicExceptionMapperTest.java @@ -0,0 +1,60 @@ +/* + * ============LICENSE_START========================================== + * org.onap.music + * =================================================================== + * Copyright (c) 2019 IBM 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. + * + * ============LICENSE_END============================================= + * ==================================================================== + */ + +package org.onap.music.exceptions; + +import org.codehaus.jackson.map.exc.UnrecognizedPropertyException; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.modules.junit4.PowerMockRunner; + +import javax.ws.rs.core.Response; +import java.io.EOFException; +import java.util.Map; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +@RunWith(PowerMockRunner.class) +public class MusicExceptionMapperTest { + + @Test + public void testToResponse() { + MusicExceptionMapper musicExceptionMapper = new MusicExceptionMapper(); + UnrecognizedPropertyException unrecognizedPropertyException = PowerMockito.mock(UnrecognizedPropertyException.class); + Response response = musicExceptionMapper.toResponse(unrecognizedPropertyException); + assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatus()); + assertTrue(((Map)response.getEntity()).get("error").toString().startsWith("Unknown field :")); + + EOFException eofException = PowerMockito.mock(EOFException.class); + response = musicExceptionMapper.toResponse(eofException); + assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatus()); + assertTrue(((Map)response.getEntity()).get("error").toString().equals("Request body cannot be empty".trim())); + + IllegalArgumentException illegalArgumentException = PowerMockito.mock(IllegalArgumentException.class); + PowerMockito.when(illegalArgumentException.getMessage()).thenReturn("ERROR MSG"); + response = musicExceptionMapper.toResponse(illegalArgumentException); + assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatus()); + assertTrue(((Map)response.getEntity()).get("error").toString().equals("ERROR MSG".trim())); + } +}
\ No newline at end of file diff --git a/src/test/java/org/onap/music/unittests/jsonobjects/JsonNotificationTest.java b/src/test/java/org/onap/music/unittests/jsonobjects/JsonNotificationTest.java new file mode 100644 index 00000000..e5b13ca8 --- /dev/null +++ b/src/test/java/org/onap/music/unittests/jsonobjects/JsonNotificationTest.java @@ -0,0 +1,116 @@ +/* + * ============LICENSE_START========================================== + * org.onap.music + * =================================================================== + * Copyright (c) 2019 IBM. + * =================================================================== + * 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.music.unittests.jsonobjects; + +import static org.junit.Assert.assertEquals; + +import java.util.HashMap; +import java.util.Map; + +import org.junit.Before; +import org.junit.Test; +import org.onap.music.datastore.jsonobjects.JsonNotification; + +public class JsonNotificationTest { + + private JsonNotification jsonNotification; + + @Before + public void setUp() + { + jsonNotification= new JsonNotification(); + } + + @Test + public void testGetSetNotify_field() + { + jsonNotification.setNotify_field("notify_field"); + assertEquals("notify_field", jsonNotification.getNotify_field()); + } + + @Test + public void testGetSetEndpoint() + { + jsonNotification.setEndpoint("endpoint"); + assertEquals("endpoint", jsonNotification.getEndpoint()); + } + + @Test + public void testGetSetUsername() + { + jsonNotification.setUsername("Username"); + assertEquals("Username", jsonNotification.getUsername()); + } + + @Test + public void testGetSetPassword() + { + jsonNotification.setPassword("Password"); + assertEquals("Password", jsonNotification.getPassword()); + } + + @Test + public void testGetSetResponse_body() + { + Map<String, String> ResponseBody= new HashMap<>(); + jsonNotification.setResponse_body(ResponseBody); + assertEquals(ResponseBody, jsonNotification.getResponse_body()); + } + + @Test + public void testGetSetNotify_change() + { + jsonNotification.setNotify_change("Notify_change"); + assertEquals("Notify_change", jsonNotification.getNotify_change()); + } + + @Test + public void testGetSetNotify_insert() + { + jsonNotification.setNotify_insert("Notify_insert"); + assertEquals("Notify_insert", jsonNotification.getNotify_insert()); + } + + @Test + public void testGetSetNotify_delete() + { + jsonNotification.setNotify_delete("Notify_delete"); + assertEquals("Notify_delete", jsonNotification.getNotify_delete()); + } + + @Test + public void testGetSetOperation_type() + { + jsonNotification.setOperation_type("Operation_type"); + assertEquals("Operation_type", jsonNotification.getOperation_type()); + } + + @Test + public void testGetSetTriggerName() + { + jsonNotification.setTriggerName("TriggerName"); + assertEquals("TriggerName", jsonNotification.getTriggerName()); + } + + +} diff --git a/src/test/java/org/onap/music/unittests/jsonobjects/JsonSelectTest.java b/src/test/java/org/onap/music/unittests/jsonobjects/JsonSelectTest.java index 0243232f..f776e546 100644 --- a/src/test/java/org/onap/music/unittests/jsonobjects/JsonSelectTest.java +++ b/src/test/java/org/onap/music/unittests/jsonobjects/JsonSelectTest.java @@ -4,6 +4,8 @@ * =================================================================== * Copyright (c) 2017 AT&T Intellectual Property * =================================================================== + * Modifications Copyright (c) 2018-2019 IBM + * =================================================================== * 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 @@ -21,9 +23,12 @@ */ package org.onap.music.unittests.jsonobjects; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; + +import java.io.IOException; import java.util.HashMap; import java.util.Map; + import org.junit.Test; import org.onap.music.datastore.jsonobjects.JsonSelect; @@ -35,7 +40,16 @@ public class JsonSelectTest { Map<String, String> mapSs = new HashMap<>(); mapSs.put("k1", "one"); js.setConsistencyInfo(mapSs); - assertEquals("one",js.getConsistencyInfo().get("k1")); + assertEquals("one", js.getConsistencyInfo().get("k1")); + } + + @Test + public void testSerialize() throws IOException { + JsonSelect js = new JsonSelect(); + Map<String, String> mapSs = new HashMap<>(); + mapSs.put("Key", "Value"); + js.setConsistencyInfo(mapSs); + js.serialize(); } } |