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