From: Balaji, Ramya (rb111y) Date: Mon, 19 Mar 2018 16:50:52 +0000 (-0400) Subject: Code changes to fix Exception X-Git-Tag: v1.3.0~136 X-Git-Url: https://gerrit.onap.org/r/gitweb?a=commitdiff_plain;ds=sidebyside;h=f06b023ebfa4ce22a58e6548b817264dbb6eea61;p=appc.git Code changes to fix Exception Reverted changes to method name in Transaction.java to getuId() as this caused incorrect attributes to be added to the generated JSON. Added unit test to ensure this works as expected in the future. Issue-ID: APPC-760 Change-Id: I07adcda0b5f04bd00efc113b94c68f48af13ad78 Signed-off-by: Balaji, Ramya (rb111y) --- diff --git a/appc-config/appc-flow-controller/provider/src/main/java/org/onap/appc/flow/controller/data/Transaction.java b/appc-config/appc-flow-controller/provider/src/main/java/org/onap/appc/flow/controller/data/Transaction.java index 2eb75ff7a..327028f00 100644 --- a/appc-config/appc-flow-controller/provider/src/main/java/org/onap/appc/flow/controller/data/Transaction.java +++ b/appc-config/appc-flow-controller/provider/src/main/java/org/onap/appc/flow/controller/data/Transaction.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP : APPC * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-18 AT&T Intellectual Property. All rights reserved. * ============================================================================= * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -77,7 +77,7 @@ public class Transaction { private String status = "PENDING"; - public String getId() { + public String getuId() { return uId; } diff --git a/appc-config/appc-flow-controller/provider/src/main/java/org/onap/appc/flow/controller/executorImpl/RestExecutor.java b/appc-config/appc-flow-controller/provider/src/main/java/org/onap/appc/flow/controller/executorImpl/RestExecutor.java index 2f64a21c6..d18f2a3e2 100644 --- a/appc-config/appc-flow-controller/provider/src/main/java/org/onap/appc/flow/controller/executorImpl/RestExecutor.java +++ b/appc-config/appc-flow-controller/provider/src/main/java/org/onap/appc/flow/controller/executorImpl/RestExecutor.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP : APPC * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-18 AT&T Intellectual Property. All rights reserved. * ============================================================================= * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -65,7 +65,7 @@ public class RestExecutor implements FlowExecutorInterface { HTTPSProperties.PROPERTY_HTTPS_PROPERTIES, new HTTPSProperties(getHostnameVerifier(), sslContext)); client = createClient(defaultClientConfig); - client.addFilter(new HTTPBasicAuthFilter(transaction.getId(), transaction.getPswd())); + client.addFilter(new HTTPBasicAuthFilter(transaction.getuId(), transaction.getPswd())); WebResource webResource = client.resource(new URI(transaction.getExecutionEndPoint())); webResource.setProperty("Content-Type", "application/json;charset=UTF-8"); diff --git a/appc-config/appc-flow-controller/provider/src/test/java/org/onap/appc/flow/controller/node/MapperTest.java b/appc-config/appc-flow-controller/provider/src/test/java/org/onap/appc/flow/controller/node/MapperTest.java new file mode 100644 index 000000000..dfeb4971a --- /dev/null +++ b/appc-config/appc-flow-controller/provider/src/test/java/org/onap/appc/flow/controller/node/MapperTest.java @@ -0,0 +1,67 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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.appc.flow.controller.node; + +import static org.junit.Assert.assertEquals; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.Test; +import org.onap.appc.flow.controller.data.Transaction; +import org.onap.appc.flow.controller.data.Transactions; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; + +/* + * Adding this test case to ensure that JSON mapping works as expected. + * Add or modify test case if changes are made to class attributes. + * +*/ +public class MapperTest { + + @Test + public void testsIfJsonGenerationisValid() throws JsonProcessingException { + + Transaction t = new Transaction(); + Transactions transactions = new Transactions(); + t.setAction("testAction"); + t.setTransactionId(100); + t.setActionLevel("testActionLevel"); + t.setExecutionRPC("testMethod"); + List tList = new ArrayList(); + tList.add(t); + transactions.setTransactions(tList); + Transactions trans = transactions; + ObjectMapper mapper = new ObjectMapper(); + String flowSequence = mapper.writeValueAsString(trans); + String compareString = "{\"transactions\":[{\"executionType\":null,\"uId\":null,\"statusCode\":null,\"pswd\":null," + + "\"executionEndPoint\":null,\"executionModule\":null,\"executionRPC\":\"testMethod\"," + + "\"status\":\"PENDING\",\"transaction-id\":100,\"action\":\"testAction\"," + + "\"action-level\":\"testActionLevel\",\"action-identifier\":null," + + "\"parameters\":null,\"state\":null,\"precheck\":null,\"payload\":null,\"responses\":null}]}"; + assertEquals(flowSequence, compareString); + + } + +} diff --git a/appc-config/appc-flow-controller/provider/src/test/java/org/onap/appc/flow/controller/node/TransactionHandlerTest.java b/appc-config/appc-flow-controller/provider/src/test/java/org/onap/appc/flow/controller/node/TransactionHandlerTest.java index f16dd65cc..637a9ea6e 100644 --- a/appc-config/appc-flow-controller/provider/src/test/java/org/onap/appc/flow/controller/node/TransactionHandlerTest.java +++ b/appc-config/appc-flow-controller/provider/src/test/java/org/onap/appc/flow/controller/node/TransactionHandlerTest.java @@ -1,3 +1,24 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * 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.appc.flow.controller.node; import static org.mockito.Mockito.mock; @@ -69,8 +90,8 @@ public class TransactionHandlerTest { Assert.assertEquals(INPUT_REQUEST_ACTION, transaction.getAction()); Assert.assertEquals("input-ra-type", transaction.getExecutionRPC()); Assert.assertEquals("some uri", transaction.getExecutionEndPoint()); - Assert.assertEquals("rest-user", transaction.getId()); + Assert.assertEquals("rest-user", transaction.getuId()); Assert.assertEquals("rest-pass", transaction.getPswd()); } -} \ No newline at end of file +}