2 * Copyright (C) 2016 ZTE, Inc. and others. All rights reserved. (ZTE)
\r
4 * Licensed under the Apache License, Version 2.0 (the "License");
\r
5 * you may not use this file except in compliance with the License.
\r
6 * You may obtain a copy of the License at
\r
8 * http://www.apache.org/licenses/LICENSE-2.0
\r
10 * Unless required by applicable law or agreed to in writing, software
\r
11 * distributed under the License is distributed on an "AS IS" BASIS,
\r
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
13 * See the License for the specific language governing permissions and
\r
14 * limitations under the License.
\r
16 package org.openo.msb.wrapper;
\r
18 import java.util.HashSet;
\r
19 import java.util.Set;
\r
21 import org.junit.After;
\r
22 import org.junit.Assert;
\r
23 import org.junit.Before;
\r
24 import org.junit.BeforeClass;
\r
25 import org.junit.Test;
\r
26 import org.openo.msb.api.MicroServiceFullInfo;
\r
27 import org.openo.msb.api.MicroServiceInfo;
\r
28 import org.openo.msb.api.Node;
\r
29 import org.openo.msb.api.exception.ExtendedInternalServerErrorException;
\r
30 import org.openo.msb.api.exception.ExtendedNotFoundException;
\r
32 public class MicroServiceWrapperTest {
\r
33 private static MicroServiceWrapper microServiceWrapper;
\r
36 public static void setUpBeforeClass() throws Exception {
\r
37 microServiceWrapper=microServiceWrapper.getInstance();
\r
41 public void setUp() {
\r
42 MicroServiceInfo microServiceInfo=new MicroServiceInfo();
\r
43 microServiceInfo.setServiceName("testForJunit");
\r
44 microServiceInfo.setVersion("v1");
\r
45 microServiceInfo.setUrl("/api/test/v1");
\r
46 microServiceInfo.setProtocol("REST");
\r
47 microServiceInfo.setVisualRange("0");
\r
48 Set<Node> nodes=new HashSet<Node>();
\r
49 nodes.add(new Node("127.0.0.1","8080",0));
\r
50 microServiceInfo.setNodes(nodes);
\r
52 microServiceWrapper.saveMicroServiceInstance(microServiceInfo,true,"","");
\r
53 }catch(ExtendedInternalServerErrorException e){
\r
56 Assert.fail("Exception" + e.getMessage());
\r
62 public void tearDown() {
\r
64 microServiceWrapper.deleteMicroService("testForJunit", "v1", "");
\r
65 }catch(ExtendedInternalServerErrorException e){
\r
66 } catch (Exception e) {
\r
67 Assert.fail("Exception" + e.getMessage());
\r
72 public void testGetAllMicroServiceInstances(){
\r
74 MicroServiceFullInfo[] MicroServiceInfoList=microServiceWrapper.getAllMicroServiceInstances();
\r
75 Assert.assertTrue(MicroServiceInfoList.length >= 0);
\r
76 }catch(ExtendedInternalServerErrorException e){
\r
79 Assert.fail("Exception" + e.getMessage());
\r
85 public void testGetMicroServiceInstance_not_exist(){
\r
86 MicroServiceFullInfo microServiceInfo = null;
\r
88 microServiceInfo=microServiceWrapper.getMicroServiceInstance("testForJunit", "v2","");
\r
89 Assert.assertNotNull(microServiceInfo);
\r
90 }catch(ExtendedInternalServerErrorException e){
\r
92 catch(ExtendedNotFoundException e){
\r
93 Assert.assertNull(microServiceInfo);
\r
99 public void testGetMicroServiceInstance_exist(){
\r
101 MicroServiceFullInfo microServiceInfo=microServiceWrapper.getMicroServiceInstance("testForJunit", "v1","");
\r
102 Assert.assertNotNull(microServiceInfo);
\r
103 }catch(ExtendedInternalServerErrorException e){
\r
105 catch(Exception e){
\r
106 Assert.fail("Exception" + e.getMessage());
\r
112 public void testUpdateMicroServiceInstance(){
\r
115 MicroServiceInfo microServiceInfo=new MicroServiceInfo();
\r
116 microServiceInfo.setServiceName("testForJunit");
\r
117 microServiceInfo.setVersion("v1");
\r
118 microServiceInfo.setUrl("/api/test2/v1");
\r
119 microServiceInfo.setProtocol("REST");
\r
120 microServiceInfo.setVisualRange("0");
\r
121 Set<Node> nodes=new HashSet<Node>();
\r
122 nodes.add(new Node("127.0.0.1","8080",0));
\r
123 microServiceInfo.setNodes(nodes);
\r
125 MicroServiceFullInfo new_MicroServiceInfo= microServiceWrapper.updateMicroServiceInstance("testForJunit", "v1", microServiceInfo);
\r
126 Assert.assertEquals("/api/test2/v1", new_MicroServiceInfo.getUrl());
\r
127 }catch(ExtendedInternalServerErrorException e){
\r
129 catch(Exception e){
\r
130 Assert.fail("Exception" + e.getMessage());
\r
136 public void testUpdateMicroServiceStatus(){
\r
138 MicroServiceFullInfo new_MicroServiceInfo= microServiceWrapper.updateMicroServiceStatus("testForJunit", "v1", "0");
\r
139 Assert.assertEquals("0",new_MicroServiceInfo.getStatus());
\r
140 }catch(ExtendedInternalServerErrorException e){
\r
141 }catch(Exception e){
\r
142 Assert.fail("Exception" + e.getMessage());
\r