3774332b23be3a3e766454203a58e4c656ccc019
[sdc.git] / catalog-be / src / test / java / org / openecomp / sdc / be / components / path / beans / ForwardingPathToscaOperationFacade.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 2019 AT&T Intellectual Property. 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
21 package org.openecomp.sdc.be.components.path.beans;
22
23 import fj.data.Either;
24 import org.apache.commons.lang3.StringUtils;
25 import org.openecomp.sdc.be.impl.ForwardingPathUtils;
26 import org.openecomp.sdc.be.model.Component;
27 import org.openecomp.sdc.be.model.Resource;
28 import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaOperationFacade;
29 import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
30
31 @org.springframework.stereotype.Component("tosca-operation-facade")
32 public class ForwardingPathToscaOperationFacade extends ToscaOperationFacade {
33     protected static final String GENERIC_SERVICE_NAME = "org.openecomp.resource.abstract.nodes.service";
34     @Override
35     public Either<Resource, StorageOperationStatus> getLatestCertifiedNodeTypeByToscaResourceName(String toscaResourceName) {
36
37         return Either.left(setupGenericServiceMock());
38     }
39
40     protected Resource setupGenericServiceMock(){
41         Resource genericService = new Resource();
42         genericService.setVersion("1.0");
43         genericService.setToscaResourceName(GENERIC_SERVICE_NAME);
44         return genericService;
45     }
46
47     @Override
48     public <T extends Component> Either<T, StorageOperationStatus> getLatestByName(String resourceName, String model) {
49         if(resourceName.equals(ForwardingPathUtils.FORWARDING_PATH_NODE_NAME) || resourceName.equals(ForwardingPathUtils.FORWARDER_CAPABILITY)){
50             Resource component = new Resource();
51             component.setToscaResourceName(GENERIC_SERVICE_NAME);
52             return Either.left((T)component);
53         }
54         return super.getLatestByName(resourceName, null);
55     }
56
57     @Override
58     public <T extends Component> Either<T, StorageOperationStatus> getLatestByToscaResourceName(String toscaResourceName) {
59         if(toscaResourceName.equals(ForwardingPathUtils.FORWARDING_PATH_NODE_NAME) || toscaResourceName.equals(ForwardingPathUtils.FORWARDER_CAPABILITY)){
60             Resource component = new Resource();
61             component.setToscaResourceName(GENERIC_SERVICE_NAME);
62             return Either.left((T)component);
63         }
64         return super.getLatestByToscaResourceName(toscaResourceName);
65     }
66 }