Added oparent to sdc main
[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.openecomp.sdc.be.impl.ForwardingPathUtils;
25 import org.openecomp.sdc.be.model.Component;
26 import org.openecomp.sdc.be.model.Resource;
27 import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaOperationFacade;
28 import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
29
30 @org.springframework.stereotype.Component("tosca-operation-facade")
31 public class ForwardingPathToscaOperationFacade extends ToscaOperationFacade {
32     protected static final String GENERIC_SERVICE_NAME = "org.openecomp.resource.abstract.nodes.service";
33     @Override
34     public Either<Resource, StorageOperationStatus> getLatestCertifiedNodeTypeByToscaResourceName(String toscaResourceName) {
35
36         return Either.left(setupGenericServiceMock());
37     }
38
39     protected Resource setupGenericServiceMock(){
40         Resource genericService = new Resource();
41         genericService.setVersion("1.0");
42         genericService.setToscaResourceName(GENERIC_SERVICE_NAME);
43         return genericService;
44     }
45
46     @Override
47     public <T extends Component> Either<T, StorageOperationStatus> getLatestByName(String resourceName) {
48         if(resourceName.equals(ForwardingPathUtils.FORWARDING_PATH_NODE_NAME) || resourceName.equals(ForwardingPathUtils.FORWARDER_CAPABILITY)){
49             Resource component = new Resource();
50             component.setToscaResourceName(GENERIC_SERVICE_NAME);
51             return Either.left((T)component);
52         }
53         return super.getLatestByName(resourceName);
54     }
55
56     @Override
57     public <T extends Component> Either<T, StorageOperationStatus> getLatestByToscaResourceName(String toscaResourceName) {
58         if(toscaResourceName.equals(ForwardingPathUtils.FORWARDING_PATH_NODE_NAME) || toscaResourceName.equals(ForwardingPathUtils.FORWARDER_CAPABILITY)){
59             Resource component = new Resource();
60             component.setToscaResourceName(GENERIC_SERVICE_NAME);
61             return Either.left((T)component);
62         }
63         return super.getLatestByToscaResourceName(toscaResourceName);
64     }
65 }