Add junit coverage to RequestInfoBuilder class
[appc.git] / appc-config / appc-flow-controller / provider / src / main / java / org / onap / appc / flow / controller / node / TransactionHandler.java
1 /*
2  * ============LICENSE_START=======================================================
3  * ONAP : APPC
4  * ================================================================================
5  * Copyright (C) 2018 Nokia. All rights reserved.
6  * =============================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20 package org.onap.appc.flow.controller.node;
21
22 import static org.onap.appc.flow.controller.utils.FlowControllerConstants.INPUT_REQUEST_ACTION;
23 import static org.onap.appc.flow.controller.utils.FlowControllerConstants.INPUT_REQUEST_ACTION_TYPE;
24
25 import java.util.Properties;
26 import org.apache.commons.lang3.StringUtils;
27 import org.onap.appc.flow.controller.data.Transaction;
28 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
29
30 /**
31  * Helper class for RestServiceNode
32  */
33 class TransactionHandler {
34
35   Transaction buildTransaction(SvcLogicContext ctx, Properties prop, String resourceUri)
36       throws Exception {
37
38     String inputRequestAction = ctx.getAttribute(INPUT_REQUEST_ACTION);
39     String inputRequestActionType = ctx.getAttribute(INPUT_REQUEST_ACTION_TYPE);
40
41     if (StringUtils.isBlank(inputRequestActionType)) {
42       throw new Exception("Don't know REST operation for Action " + inputRequestActionType);
43     }
44     if (StringUtils.isBlank(inputRequestAction)) {
45       throw new Exception("Don't know request-action " + INPUT_REQUEST_ACTION);
46     }
47
48     Transaction transaction = new Transaction();
49     transaction.setExecutionEndPoint(resourceUri);
50     transaction.setExecutionRPC(inputRequestActionType);
51     transaction.setAction(INPUT_REQUEST_ACTION);
52
53     //This code need to get changed to get the UserID and pass from a common place.
54     transaction.setuId(prop.getProperty(inputRequestAction.concat(".default-rest-user")));
55     transaction.setPswd(prop.getProperty(inputRequestAction.concat(".default-rest-pass")));
56
57     return transaction;
58   }
59
60 }