diff options
Diffstat (limited to 'src/test/java/org')
10 files changed, 582 insertions, 2 deletions
diff --git a/src/test/java/org/onap/music/eelf/logging/format/AppMessagesTest.java b/src/test/java/org/onap/music/eelf/logging/format/AppMessagesTest.java new file mode 100644 index 00000000..cba9c7c2 --- /dev/null +++ b/src/test/java/org/onap/music/eelf/logging/format/AppMessagesTest.java @@ -0,0 +1,65 @@ +/* + * ============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.eelf.logging.format; + +import static org.junit.Assert.assertEquals; + +import org.junit.Before; +import org.junit.Test; + +public class AppMessagesTest { + + private AppMessages messages; + + @Before + public void setUp() { + messages= AppMessages.ALREADYEXIST; + } + + @Test + public void testDetails() + { + messages.setDetails("details"); + assertEquals("details", messages.getDetails()); + } + + @Test + public void testResolution() + { + messages.setResolution("Resolution"); + assertEquals("Resolution", messages.getResolution()); + } + + @Test + public void testErrorCode() + { + messages.setErrorCode("ErrorCode"); + assertEquals("ErrorCode", messages.getErrorCode()); + } + + @Test + public void testErrorDescription() + { + messages.setErrorDescription("ErrorDescription"); + assertEquals("ErrorDescription", messages.getErrorDescription()); + } +} 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/JsonResponseTest.java b/src/test/java/org/onap/music/unittests/JsonResponseTest.java index 9da10638..781cdd7b 100644 --- a/src/test/java/org/onap/music/unittests/JsonResponseTest.java +++ b/src/test/java/org/onap/music/unittests/JsonResponseTest.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 @@ -23,8 +25,11 @@ package org.onap.music.unittests; import static org.junit.Assert.*; + +import java.util.HashMap; import java.util.Map; import org.junit.Test; +import org.onap.music.lockingservice.MusicLockState.LockStatus; import org.onap.music.main.ResultType; import org.onap.music.response.jsonobjects.JsonResponse; @@ -80,4 +85,44 @@ public class JsonResponseTest { assertEquals(ResultType.FAILURE, myMap.get("status")); } + @Test + public void testMessage() { + result = new JsonResponse(ResultType.SUCCESS); + result.setMessage("message"); + assertEquals("message", result.getMessage()); + + } + + @Test + public void testDataResult() { + result = new JsonResponse(ResultType.SUCCESS); + Map<String, HashMap<String, Object>> dataResult= new HashMap<>(); + result.setDataResult(dataResult); + assertEquals(dataResult, result.getDataResult()); + + } + + @Test + public void testLock() { + result = new JsonResponse(ResultType.SUCCESS); + result.setLock("lock"); + assertEquals("lock", result.getLock()); + + } + + @Test + public void testLockStatus() { + result = new JsonResponse(ResultType.SUCCESS); + LockStatus status = LockStatus.LOCKED; + result.setLockStatus(status); + assertEquals(status, result.getLockStatus()); + + } + + @Test + public void testToString() { + result = new JsonResponse(ResultType.SUCCESS); + assertTrue(result.toString() instanceof String); + + } } diff --git a/src/test/java/org/onap/music/unittests/jsonobjects/JsonCallBackResponseTest.java b/src/test/java/org/onap/music/unittests/jsonobjects/JsonCallBackResponseTest.java new file mode 100644 index 00000000..0da99fb9 --- /dev/null +++ b/src/test/java/org/onap/music/unittests/jsonobjects/JsonCallBackResponseTest.java @@ -0,0 +1,108 @@ +/* + * ============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.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.junit.Before; +import org.junit.Test; +import org.onap.music.datastore.jsonobjects.JSONCallbackResponse; + +public class JsonCallBackResponseTest { + + private JSONCallbackResponse jsonCallBackResponse; + + @Before + public void setUp() + { + jsonCallBackResponse = new JSONCallbackResponse(); + } + + @Test + public void testFullTable() + { + jsonCallBackResponse.setFull_table("fullTable"); + assertEquals("fullTable", jsonCallBackResponse.getFull_table()); + } + + @Test + public void testKeyspace() + { + jsonCallBackResponse.setKeyspace("keyspace"); + assertEquals("keyspace", jsonCallBackResponse.getKeyspace()); + } + + @Test + public void testOperation() + { + jsonCallBackResponse.setOperation("Operation"); + assertEquals("Operation", jsonCallBackResponse.getOperation()); + } + + @Test + public void testTable_name() + { + jsonCallBackResponse.setTable_name("Table_name"); + assertEquals("Table_name", jsonCallBackResponse.getTable_name()); + } + + + @Test + public void testPrimary_key() + { + jsonCallBackResponse.setPrimary_key("Primary_key"); + assertEquals("Primary_key", jsonCallBackResponse.getPrimary_key()); + } + + + @Test + public void testMiscObjects() + { + jsonCallBackResponse.setMiscObjects("MiscObjects"); + assertEquals("MiscObjects", jsonCallBackResponse.getMiscObjects()); + } + + @Test + public void testChangeValue() + { + Map<String, String> changeValue = new HashMap<>(); + jsonCallBackResponse.setChangeValue(changeValue); + assertEquals(changeValue, jsonCallBackResponse.getChangeValue()); + } + + @Test + public void testUpdateList() + { + List<String> list= new ArrayList<>(); + jsonCallBackResponse.setUpdateList(list); + assertEquals(list, jsonCallBackResponse.getUpdateList()); + } + + + +} diff --git a/src/test/java/org/onap/music/unittests/jsonobjects/JsonCallBackTest.java b/src/test/java/org/onap/music/unittests/jsonobjects/JsonCallBackTest.java new file mode 100644 index 00000000..252cd1b6 --- /dev/null +++ b/src/test/java/org/onap/music/unittests/jsonobjects/JsonCallBackTest.java @@ -0,0 +1,103 @@ +/* + * ============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.JsonCallback; + +public class JsonCallBackTest { + private JsonCallback jsonCallBack; + + @Before + public void setUp() { + jsonCallBack = new JsonCallback(); + } + + @Test + public void testUuid() { + jsonCallBack.setUuid("uuid"); + assertEquals("uuid", jsonCallBack.getUuid()); + } + + @Test + public void testApplicationName() { + jsonCallBack.setApplicationName("ApplicationName"); + assertEquals("ApplicationName", jsonCallBack.getApplicationName()); + } + + @Test + public void testNotifyOn() { + jsonCallBack.setNotifyOn("NotifyOn"); + assertEquals("NotifyOn", jsonCallBack.getNotifyOn()); + } + + @Test + public void testApplicationUsername() { + jsonCallBack.setApplicationUsername("ApplicationUsername"); + assertEquals("ApplicationUsername", jsonCallBack.getApplicationUsername()); + } + + @Test + public void testApplicationPassword() { + jsonCallBack.setApplicationPassword("ApplicationPassword"); + assertEquals("ApplicationPassword", jsonCallBack.getApplicationPassword()); + } + + @Test + public void testApplicationNotificationEndpoint() { + jsonCallBack.setApplicationNotificationEndpoint("ApplicationNotificationEndpoint"); + assertEquals("ApplicationNotificationEndpoint", jsonCallBack.getApplicationNotificationEndpoint()); + } + + @Test + public void testNotifyWhenChangeIn() { + jsonCallBack.setNotifyWhenChangeIn("NotifyWhenChangeIn"); + assertEquals("NotifyWhenChangeIn", jsonCallBack.getNotifyWhenChangeIn()); + } + + @Test + public void testNotifyWhenInsertsIn() { + jsonCallBack.setNotifyWhenInsertsIn("NotifyWhenInsertsIn"); + assertEquals("NotifyWhenInsertsIn", jsonCallBack.getNotifyWhenInsertsIn()); + } + + @Test + public void testNotifyWhenDeletesIn() { + jsonCallBack.setNotifyWhenDeletesIn("NotifyWhenDeletesIn"); + assertEquals("NotifyWhenDeletesIn", jsonCallBack.getNotifyWhenDeletesIn()); + } + + @Test + public void testResponseBody() { + Map<String, String> response = new HashMap<>(); + jsonCallBack.setResponseBody(response); + assertEquals(response, jsonCallBack.getResponseBody()); + } + +} 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(); } } diff --git a/src/test/java/org/onap/music/unittests/jsonobjects/JsonTableTest.java b/src/test/java/org/onap/music/unittests/jsonobjects/JsonTableTest.java index e4c800fc..2279cf0b 100644 --- a/src/test/java/org/onap/music/unittests/jsonobjects/JsonTableTest.java +++ b/src/test/java/org/onap/music/unittests/jsonobjects/JsonTableTest.java @@ -4,6 +4,8 @@ * =================================================================== * Copyright (c) 2017 AT&T Intellectual Property * =================================================================== + * Modifications 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 @@ -95,5 +97,11 @@ public class JsonTableTest { jt.setPrimaryKey(primaryKey); assertEquals(primaryKey,jt.getPrimaryKey()); } + + @Test + public void testFilteringKey() { + jt.setFilteringKey("FilteringKey"); + assertEquals("FilteringKey",jt.getFilteringKey()); + } } diff --git a/src/test/java/org/onap/music/unittests/jsonobjects/JsonUpdateTest.java b/src/test/java/org/onap/music/unittests/jsonobjects/JsonUpdateTest.java index 54db0540..2186e496 100644 --- a/src/test/java/org/onap/music/unittests/jsonobjects/JsonUpdateTest.java +++ b/src/test/java/org/onap/music/unittests/jsonobjects/JsonUpdateTest.java @@ -4,6 +4,8 @@ * =================================================================== * Copyright (c) 2018 AT&T Intellectual Property * =================================================================== + * Modifications 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 @@ -99,5 +101,10 @@ public class JsonUpdateTest { ju.setValues(cons); assertEquals("one",ju.getValues().get("val1")); } + + @Test + public void testSerialize() { + assertTrue(ju.serialize() instanceof byte[]); + } } diff --git a/src/test/java/org/onap/music/unittests/jsonobjects/MusicHealthCheckTest.java b/src/test/java/org/onap/music/unittests/jsonobjects/MusicHealthCheckTest.java new file mode 100644 index 00000000..f48ecd40 --- /dev/null +++ b/src/test/java/org/onap/music/unittests/jsonobjects/MusicHealthCheckTest.java @@ -0,0 +1,54 @@ +/* + * ============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 org.junit.Before; +import org.junit.Test; +import org.onap.music.eelf.healthcheck.MusicHealthCheck; + +public class MusicHealthCheckTest { + + private MusicHealthCheck musicHealthCheck; + + @Before + public void setUp() + { + musicHealthCheck= new MusicHealthCheck(); + } + + @Test + public void testCassandraHost() + { + musicHealthCheck.setCassandrHost("9042"); + assertEquals("9042", musicHealthCheck.getCassandrHost()); + } + + @Test + public void testZookeeperHost() + { + musicHealthCheck.setZookeeperHost("ZookeeperHost"); + assertEquals("ZookeeperHost", musicHealthCheck.getZookeeperHost()); + } +} |