From 36a7dbfd2672ee6629c4b375df2d6982d942fa43 Mon Sep 17 00:00:00 2001 From: "Sotiropoulos, Ioannis (is948x)" Date: Wed, 6 Jun 2018 15:37:35 +0100 Subject: Add tests for X-FromMsId Add tests for X-FromMsId header parameter changes Issue-ID: AAI-1198 Change-Id: I6342cf95e5c635b500245bfa90040376ffa1b992 Signed-off-by: Sotiropoulos, Ioannis (is948x) --- src/test/java/org/onap/crud/dao/TestDao.java | 194 +++++++++ .../onap/crud/event/GraphEventEnvelopeTest.java | 2 +- .../response/GraphEventResponseHandlerTest.java | 2 +- .../org/onap/crud/logging/LoggingUtilTest.java | 52 +++ .../org/onap/crud/service/CrudRestServiceTest.java | 14 + src/test/java/org/onap/crud/service/TestDao.java | 194 --------- .../java/org/onap/crud/service/TestHeaders.java | 102 ----- .../java/org/onap/crud/service/TestRequest.java | 459 --------------------- .../java/org/onap/crud/service/TestUriInfo.java | 148 ------- .../org/onap/crud/service/util/TestHeaders.java | 103 +++++ .../org/onap/crud/service/util/TestRequest.java | 459 +++++++++++++++++++++ .../org/onap/crud/service/util/TestUriInfo.java | 148 +++++++ .../java/org/onap/crud/test/util/TestUtil.java | 58 --- .../org/onap/crud/util/CrudServiceUtilTest.java | 54 +++ src/test/java/org/onap/crud/util/TestUtil.java | 58 +++ 15 files changed, 1084 insertions(+), 963 deletions(-) create mode 100644 src/test/java/org/onap/crud/dao/TestDao.java create mode 100644 src/test/java/org/onap/crud/logging/LoggingUtilTest.java delete mode 100644 src/test/java/org/onap/crud/service/TestDao.java delete mode 100644 src/test/java/org/onap/crud/service/TestHeaders.java delete mode 100644 src/test/java/org/onap/crud/service/TestRequest.java delete mode 100644 src/test/java/org/onap/crud/service/TestUriInfo.java create mode 100644 src/test/java/org/onap/crud/service/util/TestHeaders.java create mode 100644 src/test/java/org/onap/crud/service/util/TestRequest.java create mode 100644 src/test/java/org/onap/crud/service/util/TestUriInfo.java delete mode 100644 src/test/java/org/onap/crud/test/util/TestUtil.java create mode 100644 src/test/java/org/onap/crud/util/CrudServiceUtilTest.java create mode 100644 src/test/java/org/onap/crud/util/TestUtil.java (limited to 'src/test') diff --git a/src/test/java/org/onap/crud/dao/TestDao.java b/src/test/java/org/onap/crud/dao/TestDao.java new file mode 100644 index 0000000..69ce4a3 --- /dev/null +++ b/src/test/java/org/onap/crud/dao/TestDao.java @@ -0,0 +1,194 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. + * Copyright © 2017-2018 Amdocs + * ================================================================================ + * 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.crud.dao; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Map; + +import org.onap.crud.dao.GraphDao; +import org.onap.crud.entity.Edge; +import org.onap.crud.entity.Vertex; +import org.onap.crud.exception.CrudException; + +public class TestDao implements GraphDao { + + private final String champVertex = "{" + + "\"key\": \"test-uuid\"," + + "\"type\": \"pserver\"," + + "\"properties\": {" + + "\"fqdn\": \"myhost.onap.com\"," + + "\"hostname\": \"myhost\" } }"; + + private final String champEdge = "{" + + "\"key\": \"test-uuid\"," + + "\"type\": \"tosca.relationships.HostedOn\"," + + "\"properties\": {" + + "\"prevent-delete\": \"NONE\" }," + + "\"source\": {" + + "\"key\": \"50bdab41-ad1c-4d00-952c-a0aa5d827811\", \"type\": \"vserver\"}," + + "\"target\": {" + + "\"key\": \"1d326bc7-b985-492b-9604-0d5d1f06f908\", \"type\": \"pserver\"}" + + " }"; + + @Override + public Vertex getVertex(String id, String version) throws CrudException { + return Vertex.fromJson(champVertex, "v11"); + } + + @Override + public Vertex getVertex(String id, String type, String version, Map queryParams) + throws CrudException { + return Vertex.fromJson(champVertex, "v11"); + } + + @Override + public List getVertexEdges(String id, Map queryParams) throws CrudException { + List list = new ArrayList(); + list.add(Edge.fromJson(champEdge)); + return list; + } + + @Override + public List getVertices(String type, Map filter, String version) throws CrudException { + List list = new ArrayList(); + list.add(Vertex.fromJson(champVertex, "v11")); + return list; + } + + @Override + public List getVertices(String type, Map filter, HashSet properties, String version) + throws CrudException { + List list = new ArrayList(); + list.add(Vertex.fromJson(champVertex, "v11")); + return list; + } + + @Override + public Edge getEdge(String id, String type, Map queryParams) throws CrudException { + return Edge.fromJson(champEdge); + } + + @Override + public List getEdges(String type, Map filter) throws CrudException { + List list = new ArrayList(); + list.add(Edge.fromJson(champEdge)); + return list; + } + + @Override + public Vertex addVertex(String type, Map properties, String version) throws CrudException { + return Vertex.fromJson(champVertex, "v11"); + } + + @Override + public Vertex updateVertex(String id, String type, Map properties, String version) + throws CrudException { + return Vertex.fromJson(champVertex, "v11"); + } + + @Override + public void deleteVertex(String id, String type) throws CrudException { + + } + + @Override + public Edge addEdge(String type, Vertex source, Vertex target, Map properties, String version) + throws CrudException { + return Edge.fromJson(champEdge); + } + + @Override + public Edge updateEdge(Edge edge) throws CrudException { + return Edge.fromJson(champEdge); + } + + @Override + public void deleteEdge(String id, String type) throws CrudException { + + } + + @Override + public String openTransaction() { + // TODO Auto-generated method stub + return null; + } + + @Override + public void commitTransaction(String id) throws CrudException { + // TODO Auto-generated method stub + + } + + @Override + public void rollbackTransaction(String id) throws CrudException { + // TODO Auto-generated method stub + + } + + @Override + public boolean transactionExists(String id) throws CrudException { + // TODO Auto-generated method stub + return false; + } + + @Override + public Vertex addVertex(String type, Map properties, String version, String txId) + throws CrudException { + return Vertex.fromJson(champVertex, "v11"); + } + + @Override + public Edge addEdge(String type, Vertex source, Vertex target, Map properties, String version, + String txId) throws CrudException { + return Edge.fromJson(champEdge); + } + + @Override + public Vertex updateVertex(String id, String type, Map properties, String version, String txId) + throws CrudException { + return Vertex.fromJson(champVertex, "v11"); + } + + @Override + public Edge updateEdge(Edge edge, String txId) throws CrudException { + return Edge.fromJson(champEdge); + } + + @Override + public void deleteVertex(String id, String type, String txId) throws CrudException { + // TODO Auto-generated method stub + + } + + @Override + public void deleteEdge(String id, String type, String txId) throws CrudException { + // TODO Auto-generated method stub + + } + + @Override + public Edge getEdge(String id, String type, String txId) throws CrudException { + return Edge.fromJson(champEdge); + } + +} diff --git a/src/test/java/org/onap/crud/event/GraphEventEnvelopeTest.java b/src/test/java/org/onap/crud/event/GraphEventEnvelopeTest.java index e280c95..de56992 100644 --- a/src/test/java/org/onap/crud/event/GraphEventEnvelopeTest.java +++ b/src/test/java/org/onap/crud/event/GraphEventEnvelopeTest.java @@ -26,7 +26,7 @@ import org.junit.Test; import org.onap.crud.entity.Vertex; import org.onap.crud.event.GraphEvent.GraphEventOperation; import org.onap.crud.event.envelope.GraphEventEnvelope; -import org.onap.crud.test.util.TestUtil; +import org.onap.crud.util.TestUtil; import org.skyscreamer.jsonassert.Customization; import org.skyscreamer.jsonassert.JSONAssert; import org.skyscreamer.jsonassert.JSONCompareMode; diff --git a/src/test/java/org/onap/crud/event/response/GraphEventResponseHandlerTest.java b/src/test/java/org/onap/crud/event/response/GraphEventResponseHandlerTest.java index 9330556..1829496 100644 --- a/src/test/java/org/onap/crud/event/response/GraphEventResponseHandlerTest.java +++ b/src/test/java/org/onap/crud/event/response/GraphEventResponseHandlerTest.java @@ -24,7 +24,7 @@ import static org.hamcrest.Matchers.is; import static org.junit.Assert.assertThat; import org.junit.Test; import org.onap.crud.event.envelope.GraphEventEnvelope; -import org.onap.crud.test.util.TestUtil; +import org.onap.crud.util.TestUtil; import com.google.gson.Gson; public class GraphEventResponseHandlerTest { diff --git a/src/test/java/org/onap/crud/logging/LoggingUtilTest.java b/src/test/java/org/onap/crud/logging/LoggingUtilTest.java new file mode 100644 index 0000000..bc1c9bd --- /dev/null +++ b/src/test/java/org/onap/crud/logging/LoggingUtilTest.java @@ -0,0 +1,52 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. + * Copyright © 2017-2018 Amdocs + * ================================================================================ + * 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.crud.logging; + +import org.junit.Assert; +import org.junit.Test; +import org.onap.crud.service.util.TestHeaders; + +public class LoggingUtilTest { + + @Test + public void testGetAppId() throws Exception { + // When both MsId and AppId headers populated, return MsId header to log + TestHeaders headers = new TestHeaders(); + Assert.assertEquals("sending-service", LoggingUtil.getAppId(headers)); + + // When AppId header populated, return AppId header to log + headers = new TestHeaders(); + headers.clearRequestHeader("X-FromMsId"); + Assert.assertEquals("source-of-truth", LoggingUtil.getAppId(headers)); + + // When no headers populated, return empty string + headers = new TestHeaders(); + headers.clearRequestHeader("X-FromMsId", "X-FromAppId"); + Assert.assertEquals("", LoggingUtil.getAppId(headers)); + } + + @Test + public void testGetTransactionId() throws Exception { + TestHeaders headers = new TestHeaders(); + Assert.assertEquals("1234567890", LoggingUtil.getTransactionId(headers)); + } + +} diff --git a/src/test/java/org/onap/crud/service/CrudRestServiceTest.java b/src/test/java/org/onap/crud/service/CrudRestServiceTest.java index b61f234..3d1ce12 100644 --- a/src/test/java/org/onap/crud/service/CrudRestServiceTest.java +++ b/src/test/java/org/onap/crud/service/CrudRestServiceTest.java @@ -34,7 +34,11 @@ import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; import org.mockito.Mockito; +import org.onap.crud.dao.TestDao; import org.onap.crud.exception.CrudException; +import org.onap.crud.service.util.TestHeaders; +import org.onap.crud.service.util.TestRequest; +import org.onap.crud.service.util.TestUriInfo; import org.onap.schema.RelationshipSchemaLoader; @@ -231,6 +235,16 @@ public class CrudRestServiceTest { mockService.validateRequestHeader(testHeaders); } + @Test + public void testRequestHeaderWithMsId() throws CrudException { + thrown.expect(CrudException.class); + thrown.expectMessage("Invalid request, Missing X-FromAppId header"); + + TestHeaders testHeaders = new TestHeaders(); + testHeaders.clearRequestHeader("X-TransactionId", "X-FromAppId"); + mockService.validateRequestHeader(testHeaders); + } + @Test public void testEmptyRequestHeader() throws CrudException { thrown.expect(CrudException.class); diff --git a/src/test/java/org/onap/crud/service/TestDao.java b/src/test/java/org/onap/crud/service/TestDao.java deleted file mode 100644 index 5af85f0..0000000 --- a/src/test/java/org/onap/crud/service/TestDao.java +++ /dev/null @@ -1,194 +0,0 @@ -/** - * ============LICENSE_START======================================================= - * org.onap.aai - * ================================================================================ - * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. - * Copyright © 2017-2018 Amdocs - * ================================================================================ - * 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.crud.service; - -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Map; - -import org.onap.crud.dao.GraphDao; -import org.onap.crud.entity.Edge; -import org.onap.crud.entity.Vertex; -import org.onap.crud.exception.CrudException; - -public class TestDao implements GraphDao { - - private final String champVertex = "{" + - "\"key\": \"test-uuid\"," + - "\"type\": \"pserver\"," + - "\"properties\": {" + - "\"fqdn\": \"myhost.onap.com\"," + - "\"hostname\": \"myhost\" } }"; - - private final String champEdge = "{" + - "\"key\": \"test-uuid\"," + - "\"type\": \"tosca.relationships.HostedOn\"," + - "\"properties\": {" + - "\"prevent-delete\": \"NONE\" }," + - "\"source\": {" + - "\"key\": \"50bdab41-ad1c-4d00-952c-a0aa5d827811\", \"type\": \"vserver\"}," + - "\"target\": {" + - "\"key\": \"1d326bc7-b985-492b-9604-0d5d1f06f908\", \"type\": \"pserver\"}" + - " }"; - - @Override - public Vertex getVertex(String id, String version) throws CrudException { - return Vertex.fromJson(champVertex, "v11"); - } - - @Override - public Vertex getVertex(String id, String type, String version, Map queryParams) - throws CrudException { - return Vertex.fromJson(champVertex, "v11"); - } - - @Override - public List getVertexEdges(String id, Map queryParams) throws CrudException { - List list = new ArrayList(); - list.add(Edge.fromJson(champEdge)); - return list; - } - - @Override - public List getVertices(String type, Map filter, String version) throws CrudException { - List list = new ArrayList(); - list.add(Vertex.fromJson(champVertex, "v11")); - return list; - } - - @Override - public List getVertices(String type, Map filter, HashSet properties, String version) - throws CrudException { - List list = new ArrayList(); - list.add(Vertex.fromJson(champVertex, "v11")); - return list; - } - - @Override - public Edge getEdge(String id, String type, Map queryParams) throws CrudException { - return Edge.fromJson(champEdge); - } - - @Override - public List getEdges(String type, Map filter) throws CrudException { - List list = new ArrayList(); - list.add(Edge.fromJson(champEdge)); - return list; - } - - @Override - public Vertex addVertex(String type, Map properties, String version) throws CrudException { - return Vertex.fromJson(champVertex, "v11"); - } - - @Override - public Vertex updateVertex(String id, String type, Map properties, String version) - throws CrudException { - return Vertex.fromJson(champVertex, "v11"); - } - - @Override - public void deleteVertex(String id, String type) throws CrudException { - - } - - @Override - public Edge addEdge(String type, Vertex source, Vertex target, Map properties, String version) - throws CrudException { - return Edge.fromJson(champEdge); - } - - @Override - public Edge updateEdge(Edge edge) throws CrudException { - return Edge.fromJson(champEdge); - } - - @Override - public void deleteEdge(String id, String type) throws CrudException { - - } - - @Override - public String openTransaction() { - // TODO Auto-generated method stub - return null; - } - - @Override - public void commitTransaction(String id) throws CrudException { - // TODO Auto-generated method stub - - } - - @Override - public void rollbackTransaction(String id) throws CrudException { - // TODO Auto-generated method stub - - } - - @Override - public boolean transactionExists(String id) throws CrudException { - // TODO Auto-generated method stub - return false; - } - - @Override - public Vertex addVertex(String type, Map properties, String version, String txId) - throws CrudException { - return Vertex.fromJson(champVertex, "v11"); - } - - @Override - public Edge addEdge(String type, Vertex source, Vertex target, Map properties, String version, - String txId) throws CrudException { - return Edge.fromJson(champEdge); - } - - @Override - public Vertex updateVertex(String id, String type, Map properties, String version, String txId) - throws CrudException { - return Vertex.fromJson(champVertex, "v11"); - } - - @Override - public Edge updateEdge(Edge edge, String txId) throws CrudException { - return Edge.fromJson(champEdge); - } - - @Override - public void deleteVertex(String id, String type, String txId) throws CrudException { - // TODO Auto-generated method stub - - } - - @Override - public void deleteEdge(String id, String type, String txId) throws CrudException { - // TODO Auto-generated method stub - - } - - @Override - public Edge getEdge(String id, String type, String txId) throws CrudException { - return Edge.fromJson(champEdge); - } - -} diff --git a/src/test/java/org/onap/crud/service/TestHeaders.java b/src/test/java/org/onap/crud/service/TestHeaders.java deleted file mode 100644 index 835840f..0000000 --- a/src/test/java/org/onap/crud/service/TestHeaders.java +++ /dev/null @@ -1,102 +0,0 @@ -/** - * ============LICENSE_START======================================================= - * org.onap.aai - * ================================================================================ - * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. - * Copyright © 2017-2018 Amdocs - * ================================================================================ - * 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.crud.service; - -import java.util.Date; -import java.util.List; -import java.util.Locale; -import java.util.Map; - -import javax.ws.rs.core.Cookie; -import javax.ws.rs.core.HttpHeaders; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.MultivaluedHashMap; -import javax.ws.rs.core.MultivaluedMap; - -public class TestHeaders implements HttpHeaders { - - private MultivaluedMap headers; - - public TestHeaders() { - headers = new MultivaluedHashMap(); - headers.add("X-FromAppId", "test-app"); - headers.add("X-TransactionId", "65f7e29c-57fd-45b2-bfd5-19e25c59110e"); - } - - @Override - public List getAcceptableLanguages() { - return null; - } - - @Override - public List getAcceptableMediaTypes() { - return null; - } - - @Override - public Map getCookies() { - return null; - } - - @Override - public Date getDate() { - return null; - } - - @Override - public String getHeaderString(String arg0) { - return null; - } - - @Override - public Locale getLanguage() { - return null; - } - - @Override - public int getLength() { - return 0; - } - - @Override - public MediaType getMediaType() { - // TODO Auto-generated method stub - return null; - } - - @Override - public List getRequestHeader(String arg0) { - // TODO Auto-generated method stub - return null; - } - - @Override - public MultivaluedMap getRequestHeaders() { - return headers; - } - - public void clearRequestHeader(String... keys) { - for (String key : keys) { - headers.remove(key); - } - } - -} diff --git a/src/test/java/org/onap/crud/service/TestRequest.java b/src/test/java/org/onap/crud/service/TestRequest.java deleted file mode 100644 index f5ee7d6..0000000 --- a/src/test/java/org/onap/crud/service/TestRequest.java +++ /dev/null @@ -1,459 +0,0 @@ -/** - * ============LICENSE_START======================================================= - * org.onap.aai - * ================================================================================ - * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. - * Copyright © 2017-2018 Amdocs - * ================================================================================ - * 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.crud.service; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.UnsupportedEncodingException; -import java.security.Principal; -import java.util.Collection; -import java.util.Enumeration; -import java.util.Locale; -import java.util.Map; - -import javax.servlet.AsyncContext; -import javax.servlet.DispatcherType; -import javax.servlet.RequestDispatcher; -import javax.servlet.ServletContext; -import javax.servlet.ServletException; -import javax.servlet.ServletInputStream; -import javax.servlet.ServletRequest; -import javax.servlet.ServletResponse; -import javax.servlet.http.Cookie; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import javax.servlet.http.HttpSession; -import javax.servlet.http.HttpUpgradeHandler; -import javax.servlet.http.Part; - -public class TestRequest implements HttpServletRequest { - - @Override - public AsyncContext getAsyncContext() { - // TODO Auto-generated method stub - return null; - } - - @Override - public Object getAttribute(String arg0) { - // TODO Auto-generated method stub - return null; - } - - @Override - public Enumeration getAttributeNames() { - // TODO Auto-generated method stub - return null; - } - - @Override - public String getCharacterEncoding() { - // TODO Auto-generated method stub - return null; - } - - @Override - public int getContentLength() { - // TODO Auto-generated method stub - return 0; - } - - @Override - public long getContentLengthLong() { - // TODO Auto-generated method stub - return 0; - } - - @Override - public String getContentType() { - // TODO Auto-generated method stub - return null; - } - - @Override - public DispatcherType getDispatcherType() { - // TODO Auto-generated method stub - return null; - } - - @Override - public ServletInputStream getInputStream() throws IOException { - // TODO Auto-generated method stub - return null; - } - - @Override - public String getLocalAddr() { - // TODO Auto-generated method stub - return null; - } - - @Override - public String getLocalName() { - // TODO Auto-generated method stub - return null; - } - - @Override - public int getLocalPort() { - // TODO Auto-generated method stub - return 0; - } - - @Override - public Locale getLocale() { - // TODO Auto-generated method stub - return null; - } - - @Override - public Enumeration getLocales() { - // TODO Auto-generated method stub - return null; - } - - @Override - public String getParameter(String arg0) { - // TODO Auto-generated method stub - return null; - } - - @Override - public Map getParameterMap() { - // TODO Auto-generated method stub - return null; - } - - @Override - public Enumeration getParameterNames() { - // TODO Auto-generated method stub - return null; - } - - @Override - public String[] getParameterValues(String arg0) { - // TODO Auto-generated method stub - return null; - } - - @Override - public String getProtocol() { - // TODO Auto-generated method stub - return null; - } - - @Override - public BufferedReader getReader() throws IOException { - // TODO Auto-generated method stub - return null; - } - - @Override - public String getRealPath(String arg0) { - // TODO Auto-generated method stub - return null; - } - - @Override - public String getRemoteAddr() { - return "127.0.0.1"; - } - - @Override - public String getRemoteHost() { - return "127.0.0.1"; - } - - @Override - public int getRemotePort() { - // TODO Auto-generated method stub - return 0; - } - - @Override - public RequestDispatcher getRequestDispatcher(String arg0) { - // TODO Auto-generated method stub - return null; - } - - @Override - public String getScheme() { - // TODO Auto-generated method stub - return null; - } - - @Override - public String getServerName() { - // TODO Auto-generated method stub - return null; - } - - @Override - public int getServerPort() { - // TODO Auto-generated method stub - return 0; - } - - @Override - public ServletContext getServletContext() { - // TODO Auto-generated method stub - return null; - } - - @Override - public boolean isAsyncStarted() { - // TODO Auto-generated method stub - return false; - } - - @Override - public boolean isAsyncSupported() { - // TODO Auto-generated method stub - return false; - } - - @Override - public boolean isSecure() { - // TODO Auto-generated method stub - return false; - } - - @Override - public void removeAttribute(String arg0) { - // TODO Auto-generated method stub - - } - - @Override - public void setAttribute(String arg0, Object arg1) { - // TODO Auto-generated method stub - - } - - @Override - public void setCharacterEncoding(String arg0) throws UnsupportedEncodingException { - // TODO Auto-generated method stub - - } - - @Override - public AsyncContext startAsync() throws IllegalStateException { - // TODO Auto-generated method stub - return null; - } - - @Override - public AsyncContext startAsync(ServletRequest arg0, ServletResponse arg1) throws IllegalStateException { - // TODO Auto-generated method stub - return null; - } - - @Override - public boolean authenticate(HttpServletResponse arg0) throws IOException, ServletException { - // TODO Auto-generated method stub - return false; - } - - @Override - public String changeSessionId() { - // TODO Auto-generated method stub - return null; - } - - @Override - public String getAuthType() { - // TODO Auto-generated method stub - return null; - } - - @Override - public String getContextPath() { - // TODO Auto-generated method stub - return null; - } - - @Override - public Cookie[] getCookies() { - // TODO Auto-generated method stub - return null; - } - - @Override - public long getDateHeader(String arg0) { - // TODO Auto-generated method stub - return 0; - } - - @Override - public String getHeader(String arg0) { - // TODO Auto-generated method stub - return null; - } - - @Override - public Enumeration getHeaderNames() { - // TODO Auto-generated method stub - return null; - } - - @Override - public Enumeration getHeaders(String arg0) { - // TODO Auto-generated method stub - return null; - } - - @Override - public int getIntHeader(String arg0) { - // TODO Auto-generated method stub - return 0; - } - - @Override - public String getMethod() { - return "OP"; - } - - @Override - public Part getPart(String arg0) throws IOException, ServletException { - // TODO Auto-generated method stub - return null; - } - - @Override - public Collection getParts() throws IOException, ServletException { - // TODO Auto-generated method stub - return null; - } - - @Override - public String getPathInfo() { - // TODO Auto-generated method stub - return null; - } - - @Override - public String getPathTranslated() { - // TODO Auto-generated method stub - return null; - } - - @Override - public String getQueryString() { - // TODO Auto-generated method stub - return null; - } - - @Override - public String getRemoteUser() { - // TODO Auto-generated method stub - return null; - } - - @Override - public String getRequestURI() { - // TODO Auto-generated method stub - return null; - } - - @Override - public StringBuffer getRequestURL() { - return new StringBuffer(); - } - - @Override - public String getRequestedSessionId() { - // TODO Auto-generated method stub - return null; - } - - @Override - public String getServletPath() { - // TODO Auto-generated method stub - return null; - } - - @Override - public HttpSession getSession() { - // TODO Auto-generated method stub - return null; - } - - @Override - public HttpSession getSession(boolean arg0) { - // TODO Auto-generated method stub - return null; - } - - @Override - public Principal getUserPrincipal() { - // TODO Auto-generated method stub - return null; - } - - @Override - public boolean isRequestedSessionIdFromCookie() { - // TODO Auto-generated method stub - return false; - } - - @Override - public boolean isRequestedSessionIdFromURL() { - // TODO Auto-generated method stub - return false; - } - - @Override - public boolean isRequestedSessionIdFromUrl() { - // TODO Auto-generated method stub - return false; - } - - @Override - public boolean isRequestedSessionIdValid() { - // TODO Auto-generated method stub - return false; - } - - @Override - public boolean isUserInRole(String arg0) { - // TODO Auto-generated method stub - return false; - } - - @Override - public void login(String arg0, String arg1) throws ServletException { - // TODO Auto-generated method stub - - } - - @Override - public void logout() throws ServletException { - // TODO Auto-generated method stub - - } - - @Override - public T upgrade(Class arg0) throws IOException, ServletException { - // TODO Auto-generated method stub - return null; - } - -} diff --git a/src/test/java/org/onap/crud/service/TestUriInfo.java b/src/test/java/org/onap/crud/service/TestUriInfo.java deleted file mode 100644 index 980f0da..0000000 --- a/src/test/java/org/onap/crud/service/TestUriInfo.java +++ /dev/null @@ -1,148 +0,0 @@ -/** - * ============LICENSE_START======================================================= - * org.onap.aai - * ================================================================================ - * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. - * Copyright © 2017-2018 Amdocs - * ================================================================================ - * 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.crud.service; - -import java.net.URI; -import java.util.List; - -import javax.ws.rs.core.MultivaluedHashMap; -import javax.ws.rs.core.MultivaluedMap; -import javax.ws.rs.core.PathSegment; -import javax.ws.rs.core.UriBuilder; -import javax.ws.rs.core.UriInfo; - -public class TestUriInfo implements UriInfo { - - @Override - public URI getAbsolutePath() { - // TODO Auto-generated method stub - return null; - } - - @Override - public UriBuilder getAbsolutePathBuilder() { - // TODO Auto-generated method stub - return null; - } - - @Override - public URI getBaseUri() { - // TODO Auto-generated method stub - return null; - } - - @Override - public UriBuilder getBaseUriBuilder() { - // TODO Auto-generated method stub - return null; - } - - @Override - public List getMatchedResources() { - // TODO Auto-generated method stub - return null; - } - - @Override - public List getMatchedURIs() { - // TODO Auto-generated method stub - return null; - } - - @Override - public List getMatchedURIs(boolean arg0) { - // TODO Auto-generated method stub - return null; - } - - @Override - public String getPath() { - // TODO Auto-generated method stub - return null; - } - - @Override - public String getPath(boolean arg0) { - // TODO Auto-generated method stub - return null; - } - - @Override - public MultivaluedMap getPathParameters() { - // TODO Auto-generated method stub - return null; - } - - @Override - public MultivaluedMap getPathParameters(boolean arg0) { - // TODO Auto-generated method stub - return null; - } - - @Override - public List getPathSegments() { - // TODO Auto-generated method stub - return null; - } - - @Override - public List getPathSegments(boolean arg0) { - // TODO Auto-generated method stub - return null; - } - - @Override - public MultivaluedMap getQueryParameters() { - MultivaluedMap map = new MultivaluedHashMap(); - map.add("hostname", "myhost"); - return map; - } - - @Override - public MultivaluedMap getQueryParameters(boolean arg0) { - return null; - } - - @Override - public URI getRequestUri() { - // TODO Auto-generated method stub - return null; - } - - @Override - public UriBuilder getRequestUriBuilder() { - // TODO Auto-generated method stub - return null; - } - - @Override - public URI relativize(URI arg0) { - // TODO Auto-generated method stub - return null; - } - - @Override - public URI resolve(URI arg0) { - // TODO Auto-generated method stub - return null; - } - -} diff --git a/src/test/java/org/onap/crud/service/util/TestHeaders.java b/src/test/java/org/onap/crud/service/util/TestHeaders.java new file mode 100644 index 0000000..aca276c --- /dev/null +++ b/src/test/java/org/onap/crud/service/util/TestHeaders.java @@ -0,0 +1,103 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. + * Copyright © 2017-2018 Amdocs + * ================================================================================ + * 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.crud.service.util; + +import java.util.Date; +import java.util.List; +import java.util.Locale; +import java.util.Map; + +import javax.ws.rs.core.Cookie; +import javax.ws.rs.core.HttpHeaders; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.MultivaluedHashMap; +import javax.ws.rs.core.MultivaluedMap; + +public class TestHeaders implements HttpHeaders { + + private MultivaluedMap headers; + + public TestHeaders() { + headers = new MultivaluedHashMap(); + headers.add("X-FromMsId", "sending-service"); + headers.add("X-FromAppId", "source-of-truth"); + headers.add("X-TransactionId", "1234567890"); + } + + @Override + public List getAcceptableLanguages() { + return null; + } + + @Override + public List getAcceptableMediaTypes() { + return null; + } + + @Override + public Map getCookies() { + return null; + } + + @Override + public Date getDate() { + return null; + } + + @Override + public String getHeaderString(String arg0) { + return null; + } + + @Override + public Locale getLanguage() { + return null; + } + + @Override + public int getLength() { + return 0; + } + + @Override + public MediaType getMediaType() { + // TODO Auto-generated method stub + return null; + } + + @Override + public List getRequestHeader(String arg0) { + // TODO Auto-generated method stub + return null; + } + + @Override + public MultivaluedMap getRequestHeaders() { + return headers; + } + + public void clearRequestHeader(String... keys) { + for (String key : keys) { + headers.remove(key); + } + } + +} diff --git a/src/test/java/org/onap/crud/service/util/TestRequest.java b/src/test/java/org/onap/crud/service/util/TestRequest.java new file mode 100644 index 0000000..a0c9a2e --- /dev/null +++ b/src/test/java/org/onap/crud/service/util/TestRequest.java @@ -0,0 +1,459 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. + * Copyright © 2017-2018 Amdocs + * ================================================================================ + * 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.crud.service.util; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.UnsupportedEncodingException; +import java.security.Principal; +import java.util.Collection; +import java.util.Enumeration; +import java.util.Locale; +import java.util.Map; + +import javax.servlet.AsyncContext; +import javax.servlet.DispatcherType; +import javax.servlet.RequestDispatcher; +import javax.servlet.ServletContext; +import javax.servlet.ServletException; +import javax.servlet.ServletInputStream; +import javax.servlet.ServletRequest; +import javax.servlet.ServletResponse; +import javax.servlet.http.Cookie; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; +import javax.servlet.http.HttpUpgradeHandler; +import javax.servlet.http.Part; + +public class TestRequest implements HttpServletRequest { + + @Override + public AsyncContext getAsyncContext() { + // TODO Auto-generated method stub + return null; + } + + @Override + public Object getAttribute(String arg0) { + // TODO Auto-generated method stub + return null; + } + + @Override + public Enumeration getAttributeNames() { + // TODO Auto-generated method stub + return null; + } + + @Override + public String getCharacterEncoding() { + // TODO Auto-generated method stub + return null; + } + + @Override + public int getContentLength() { + // TODO Auto-generated method stub + return 0; + } + + @Override + public long getContentLengthLong() { + // TODO Auto-generated method stub + return 0; + } + + @Override + public String getContentType() { + // TODO Auto-generated method stub + return null; + } + + @Override + public DispatcherType getDispatcherType() { + // TODO Auto-generated method stub + return null; + } + + @Override + public ServletInputStream getInputStream() throws IOException { + // TODO Auto-generated method stub + return null; + } + + @Override + public String getLocalAddr() { + // TODO Auto-generated method stub + return null; + } + + @Override + public String getLocalName() { + // TODO Auto-generated method stub + return null; + } + + @Override + public int getLocalPort() { + // TODO Auto-generated method stub + return 0; + } + + @Override + public Locale getLocale() { + // TODO Auto-generated method stub + return null; + } + + @Override + public Enumeration getLocales() { + // TODO Auto-generated method stub + return null; + } + + @Override + public String getParameter(String arg0) { + // TODO Auto-generated method stub + return null; + } + + @Override + public Map getParameterMap() { + // TODO Auto-generated method stub + return null; + } + + @Override + public Enumeration getParameterNames() { + // TODO Auto-generated method stub + return null; + } + + @Override + public String[] getParameterValues(String arg0) { + // TODO Auto-generated method stub + return null; + } + + @Override + public String getProtocol() { + // TODO Auto-generated method stub + return null; + } + + @Override + public BufferedReader getReader() throws IOException { + // TODO Auto-generated method stub + return null; + } + + @Override + public String getRealPath(String arg0) { + // TODO Auto-generated method stub + return null; + } + + @Override + public String getRemoteAddr() { + return "127.0.0.1"; + } + + @Override + public String getRemoteHost() { + return "127.0.0.1"; + } + + @Override + public int getRemotePort() { + // TODO Auto-generated method stub + return 0; + } + + @Override + public RequestDispatcher getRequestDispatcher(String arg0) { + // TODO Auto-generated method stub + return null; + } + + @Override + public String getScheme() { + // TODO Auto-generated method stub + return null; + } + + @Override + public String getServerName() { + // TODO Auto-generated method stub + return null; + } + + @Override + public int getServerPort() { + // TODO Auto-generated method stub + return 0; + } + + @Override + public ServletContext getServletContext() { + // TODO Auto-generated method stub + return null; + } + + @Override + public boolean isAsyncStarted() { + // TODO Auto-generated method stub + return false; + } + + @Override + public boolean isAsyncSupported() { + // TODO Auto-generated method stub + return false; + } + + @Override + public boolean isSecure() { + // TODO Auto-generated method stub + return false; + } + + @Override + public void removeAttribute(String arg0) { + // TODO Auto-generated method stub + + } + + @Override + public void setAttribute(String arg0, Object arg1) { + // TODO Auto-generated method stub + + } + + @Override + public void setCharacterEncoding(String arg0) throws UnsupportedEncodingException { + // TODO Auto-generated method stub + + } + + @Override + public AsyncContext startAsync() throws IllegalStateException { + // TODO Auto-generated method stub + return null; + } + + @Override + public AsyncContext startAsync(ServletRequest arg0, ServletResponse arg1) throws IllegalStateException { + // TODO Auto-generated method stub + return null; + } + + @Override + public boolean authenticate(HttpServletResponse arg0) throws IOException, ServletException { + // TODO Auto-generated method stub + return false; + } + + @Override + public String changeSessionId() { + // TODO Auto-generated method stub + return null; + } + + @Override + public String getAuthType() { + // TODO Auto-generated method stub + return null; + } + + @Override + public String getContextPath() { + // TODO Auto-generated method stub + return null; + } + + @Override + public Cookie[] getCookies() { + // TODO Auto-generated method stub + return null; + } + + @Override + public long getDateHeader(String arg0) { + // TODO Auto-generated method stub + return 0; + } + + @Override + public String getHeader(String arg0) { + // TODO Auto-generated method stub + return null; + } + + @Override + public Enumeration getHeaderNames() { + // TODO Auto-generated method stub + return null; + } + + @Override + public Enumeration getHeaders(String arg0) { + // TODO Auto-generated method stub + return null; + } + + @Override + public int getIntHeader(String arg0) { + // TODO Auto-generated method stub + return 0; + } + + @Override + public String getMethod() { + return "OP"; + } + + @Override + public Part getPart(String arg0) throws IOException, ServletException { + // TODO Auto-generated method stub + return null; + } + + @Override + public Collection getParts() throws IOException, ServletException { + // TODO Auto-generated method stub + return null; + } + + @Override + public String getPathInfo() { + // TODO Auto-generated method stub + return null; + } + + @Override + public String getPathTranslated() { + // TODO Auto-generated method stub + return null; + } + + @Override + public String getQueryString() { + // TODO Auto-generated method stub + return null; + } + + @Override + public String getRemoteUser() { + // TODO Auto-generated method stub + return null; + } + + @Override + public String getRequestURI() { + // TODO Auto-generated method stub + return null; + } + + @Override + public StringBuffer getRequestURL() { + return new StringBuffer(); + } + + @Override + public String getRequestedSessionId() { + // TODO Auto-generated method stub + return null; + } + + @Override + public String getServletPath() { + // TODO Auto-generated method stub + return null; + } + + @Override + public HttpSession getSession() { + // TODO Auto-generated method stub + return null; + } + + @Override + public HttpSession getSession(boolean arg0) { + // TODO Auto-generated method stub + return null; + } + + @Override + public Principal getUserPrincipal() { + // TODO Auto-generated method stub + return null; + } + + @Override + public boolean isRequestedSessionIdFromCookie() { + // TODO Auto-generated method stub + return false; + } + + @Override + public boolean isRequestedSessionIdFromURL() { + // TODO Auto-generated method stub + return false; + } + + @Override + public boolean isRequestedSessionIdFromUrl() { + // TODO Auto-generated method stub + return false; + } + + @Override + public boolean isRequestedSessionIdValid() { + // TODO Auto-generated method stub + return false; + } + + @Override + public boolean isUserInRole(String arg0) { + // TODO Auto-generated method stub + return false; + } + + @Override + public void login(String arg0, String arg1) throws ServletException { + // TODO Auto-generated method stub + + } + + @Override + public void logout() throws ServletException { + // TODO Auto-generated method stub + + } + + @Override + public T upgrade(Class arg0) throws IOException, ServletException { + // TODO Auto-generated method stub + return null; + } + +} diff --git a/src/test/java/org/onap/crud/service/util/TestUriInfo.java b/src/test/java/org/onap/crud/service/util/TestUriInfo.java new file mode 100644 index 0000000..f416d8b --- /dev/null +++ b/src/test/java/org/onap/crud/service/util/TestUriInfo.java @@ -0,0 +1,148 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. + * Copyright © 2017-2018 Amdocs + * ================================================================================ + * 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.crud.service.util; + +import java.net.URI; +import java.util.List; + +import javax.ws.rs.core.MultivaluedHashMap; +import javax.ws.rs.core.MultivaluedMap; +import javax.ws.rs.core.PathSegment; +import javax.ws.rs.core.UriBuilder; +import javax.ws.rs.core.UriInfo; + +public class TestUriInfo implements UriInfo { + + @Override + public URI getAbsolutePath() { + // TODO Auto-generated method stub + return null; + } + + @Override + public UriBuilder getAbsolutePathBuilder() { + // TODO Auto-generated method stub + return null; + } + + @Override + public URI getBaseUri() { + // TODO Auto-generated method stub + return null; + } + + @Override + public UriBuilder getBaseUriBuilder() { + // TODO Auto-generated method stub + return null; + } + + @Override + public List getMatchedResources() { + // TODO Auto-generated method stub + return null; + } + + @Override + public List getMatchedURIs() { + // TODO Auto-generated method stub + return null; + } + + @Override + public List getMatchedURIs(boolean arg0) { + // TODO Auto-generated method stub + return null; + } + + @Override + public String getPath() { + // TODO Auto-generated method stub + return null; + } + + @Override + public String getPath(boolean arg0) { + // TODO Auto-generated method stub + return null; + } + + @Override + public MultivaluedMap getPathParameters() { + // TODO Auto-generated method stub + return null; + } + + @Override + public MultivaluedMap getPathParameters(boolean arg0) { + // TODO Auto-generated method stub + return null; + } + + @Override + public List getPathSegments() { + // TODO Auto-generated method stub + return null; + } + + @Override + public List getPathSegments(boolean arg0) { + // TODO Auto-generated method stub + return null; + } + + @Override + public MultivaluedMap getQueryParameters() { + MultivaluedMap map = new MultivaluedHashMap(); + map.add("hostname", "myhost"); + return map; + } + + @Override + public MultivaluedMap getQueryParameters(boolean arg0) { + return null; + } + + @Override + public URI getRequestUri() { + // TODO Auto-generated method stub + return null; + } + + @Override + public UriBuilder getRequestUriBuilder() { + // TODO Auto-generated method stub + return null; + } + + @Override + public URI relativize(URI arg0) { + // TODO Auto-generated method stub + return null; + } + + @Override + public URI resolve(URI arg0) { + // TODO Auto-generated method stub + return null; + } + +} diff --git a/src/test/java/org/onap/crud/test/util/TestUtil.java b/src/test/java/org/onap/crud/test/util/TestUtil.java deleted file mode 100644 index 1fcb46e..0000000 --- a/src/test/java/org/onap/crud/test/util/TestUtil.java +++ /dev/null @@ -1,58 +0,0 @@ -/** - * ============LICENSE_START======================================================= - * org.onap.aai - * ================================================================================ - * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. - * Copyright © 2017-2018 Amdocs - * ================================================================================ - * 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.crud.test.util; - -import java.io.File; -import java.io.IOException; -import java.net.URISyntaxException; -import java.net.URL; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; - -/** - * Helper methods for locating and reading test data files. - * - */ -public class TestUtil { - - public static Path getPath(String resourceFilename) throws URISyntaxException { - URL resource = ClassLoader.getSystemResource(resourceFilename); - if (resource != null) { - return Paths.get(resource.toURI()); - } - - // If the resource is not found relative to the classpath, try to get it from the file system directly. - File file = new File(resourceFilename); - if (!file.exists()) { - throw new RuntimeException("Resource does not exist: " + resourceFilename); - } - return file.toPath(); - } - - public static String getContentUtf8(Path filePath) throws IOException { - return new String(Files.readAllBytes(filePath)); - } - - public static String getFileAsString(String resourceFilename) throws IOException, URISyntaxException { - return getContentUtf8(getPath(resourceFilename)); - } -} diff --git a/src/test/java/org/onap/crud/util/CrudServiceUtilTest.java b/src/test/java/org/onap/crud/util/CrudServiceUtilTest.java new file mode 100644 index 0000000..872586e --- /dev/null +++ b/src/test/java/org/onap/crud/util/CrudServiceUtilTest.java @@ -0,0 +1,54 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. + * Copyright © 2017-2018 Amdocs + * ================================================================================ + * 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.crud.util; + +import org.junit.Assert; +import org.junit.Test; +import org.onap.crud.service.VertexPayload; +import org.onap.crud.service.util.TestHeaders; +import com.google.gson.JsonElement; + +public class CrudServiceUtilTest { + + private final String putVertexPayload = "{" + "\"id\": \"test-uuid\"," + "\"type\": \"pserver\"," + + "\"properties\": {" + "fqdn: myhost.onap.com," + "hostname: myhost } }"; + + @Test + public void testMergeHeaderInFoToPayload() throws Exception { + TestHeaders headers = new TestHeaders(); + // X-FromAppId is used to set the source of truth + VertexPayload payload = VertexPayload.fromJson(putVertexPayload); + + JsonElement properties = CrudServiceUtil.mergeHeaderInFoToPayload(payload.getProperties(), headers, false); + Assert.assertEquals("myhost.onap.com", properties.getAsJsonObject().get("fqdn").getAsString()); + Assert.assertEquals("myhost", properties.getAsJsonObject().get("hostname").getAsString()); + Assert.assertEquals("source-of-truth", + properties.getAsJsonObject().get("last-mod-source-of-truth").getAsString()); + + properties = CrudServiceUtil.mergeHeaderInFoToPayload(payload.getProperties(), headers, true); + Assert.assertEquals("myhost.onap.com", properties.getAsJsonObject().get("fqdn").getAsString()); + Assert.assertEquals("myhost", properties.getAsJsonObject().get("hostname").getAsString()); + Assert.assertEquals("source-of-truth", + properties.getAsJsonObject().get("last-mod-source-of-truth").getAsString()); + Assert.assertEquals("source-of-truth", properties.getAsJsonObject().get("source-of-truth").getAsString()); + } + +} diff --git a/src/test/java/org/onap/crud/util/TestUtil.java b/src/test/java/org/onap/crud/util/TestUtil.java new file mode 100644 index 0000000..bfbc91b --- /dev/null +++ b/src/test/java/org/onap/crud/util/TestUtil.java @@ -0,0 +1,58 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. + * Copyright © 2017-2018 Amdocs + * ================================================================================ + * 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.crud.util; + +import java.io.File; +import java.io.IOException; +import java.net.URISyntaxException; +import java.net.URL; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; + +/** + * Helper methods for locating and reading test data files. + * + */ +public class TestUtil { + + public static Path getPath(String resourceFilename) throws URISyntaxException { + URL resource = ClassLoader.getSystemResource(resourceFilename); + if (resource != null) { + return Paths.get(resource.toURI()); + } + + // If the resource is not found relative to the classpath, try to get it from the file system directly. + File file = new File(resourceFilename); + if (!file.exists()) { + throw new RuntimeException("Resource does not exist: " + resourceFilename); + } + return file.toPath(); + } + + public static String getContentUtf8(Path filePath) throws IOException { + return new String(Files.readAllBytes(filePath)); + } + + public static String getFileAsString(String resourceFilename) throws IOException, URISyntaxException { + return getContentUtf8(getPath(resourceFilename)); + } +} -- cgit 1.2.3-korg