2 * ============LICENSE_START====================================================
\r
4 * ===========================================================================
\r
5 * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
\r
6 * ===========================================================================
\r
7 * Licensed under the Apache License, Version 2.0 (the "License");
\r
8 * you may not use this file except in compliance with the License.
\r
9 * You may obtain a copy of the License at
\r
11 * http://www.apache.org/licenses/LICENSE-2.0
\r
13 * Unless required by applicable law or agreed to in writing, software
\r
14 * distributed under the License is distributed on an "AS IS" BASIS,
\r
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
16 * See the License for the specific language governing permissions and
\r
17 * limitations under the License.
\r
18 * ============LICENSE_END====================================================
\r
21 package org.onap.aaf.auth.locate.service;
\r
23 import static org.junit.Assert.assertEquals;
\r
24 import static org.mockito.Matchers.any;
\r
25 import static org.mockito.Mockito.when;
\r
27 import java.util.ArrayList;
\r
28 import java.util.List;
\r
30 import org.junit.Before;
\r
31 import org.junit.Test;
\r
32 import org.mockito.Mock;
\r
33 import org.mockito.MockitoAnnotations;
\r
34 import org.onap.aaf.auth.dao.cass.LocateDAO;
\r
35 import org.onap.aaf.auth.dao.cass.LocateDAO.Data;
\r
36 import org.onap.aaf.auth.env.AuthzTrans;
\r
37 import org.onap.aaf.auth.layer.Result;
\r
38 import org.onap.aaf.auth.locate.mapper.Mapper;
\r
39 import org.onap.aaf.misc.env.APIException;
\r
41 import locate.v1_0.MgmtEndpoint;
\r
42 import locate.v1_0.MgmtEndpoints;
\r
44 public class JU_LocateServiceImplTest {
\r
47 private AuthzTrans trans;
\r
49 private LocateDAO locateDAO;
\r
51 private Mapper mapper;
\r
53 private Result<List<Data>> result;
\r
55 private Result endPointResult;
\r
57 private MgmtEndpoints meps;
\r
59 private MgmtEndpoint mgmtEndPoint;
\r
62 public void setup() {
\r
63 MockitoAnnotations.initMocks(this);
\r
67 public void test() throws APIException {
\r
68 LocateServiceImpl locateServiceImpl = new LocateServiceImpl(trans, locateDAO, mapper);
\r
70 assertEquals(mapper, locateServiceImpl.mapper());
\r
72 when(locateDAO.readByName(trans, "http")).thenReturn(result);
\r
73 when(mapper.endpoints(result, "1.0", "other")).thenReturn(endPointResult);
\r
75 Result output = locateServiceImpl.getEndPoints(trans, "http", "1.0", "other");
\r
77 assertEquals(endPointResult, output);
\r
79 List<MgmtEndpoint> mgmtEndPoints = new ArrayList<MgmtEndpoint>();
\r
80 mgmtEndPoints.add(mgmtEndPoint);
\r
82 when(mgmtEndPoint.getName()).thenReturn("http.Endpoint1");
\r
83 when(mgmtEndPoint.getHostname()).thenReturn("HOST1");
\r
84 when(mgmtEndPoint.getPort()).thenReturn(9090);
\r
85 when(mgmtEndPoint.getProtocol()).thenReturn("HTTP");
\r
87 when(meps.getMgmtEndpoint()).thenReturn(mgmtEndPoints);
\r
88 output = locateServiceImpl.putMgmtEndPoints(trans, meps);
\r
90 assertEquals(output.toString(), Result.ok().toString());
\r
92 when(trans.fish(any())).thenReturn(true);
\r
93 Data data = new LocateDAO.Data();
\r
94 when(mapper.locateData(mgmtEndPoint)).thenReturn(data);
\r
95 output = locateServiceImpl.removeMgmtEndPoints(trans, meps);
\r
97 assertEquals(output.toString(), Result.ok().toString());
\r