com.huawei.openstack4j.api.loadbalance.ELBServerV1Tests Maven / Gradle / Ivy
/*******************************************************************************
* Copyright 2017 HuaWei Tld
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*******************************************************************************/
package com.huawei.openstack4j.api.loadbalance;
import static org.testng.Assert.*;
import java.io.IOException;
import java.util.List;
import org.testng.annotations.Test;
import com.google.common.collect.Lists;
import com.huawei.openstack4j.api.AbstractTest;
import com.huawei.openstack4j.model.loadbalance.Server;
import com.huawei.openstack4j.model.loadbalance.ServerCreate;
import com.huawei.openstack4j.openstack.loadbalance.domain.ELBJob;
import com.huawei.openstack4j.openstack.loadbalance.domain.ELBServerCreate;
import com.huawei.openstack4j.openstack.loadbalance.options.ELBServerListOptions;
import com.huawei.openstack4j.openstack.loadbalance.options.ELBServerListOptions.HealthStatus;
@Test(suiteName = "ELBLoadBalancer/ServerV1")
public class ELBServerV1Tests extends AbstractTest {
private static final String JSON_SERVER_JOB = "/loadbalance/elb_server_job.json";
private static final String JSON_SERVER_LIST = "/loadbalance/elb_server_list.json";
private static final String JSON_SERVER_LIST2 = "/loadbalance/elb_server_list2.json";
public void testCreateServer() throws IOException {
respondWith(JSON_SERVER_JOB);
String listenerId = "3a9fe2c9703c43e1ab761552a022c11e";
String serverId = "a43d86c8-c2af-4c50-9b14-d32f99874885";
ServerCreate server = ELBServerCreate.builder().serverId(serverId).address("127.0.0.1").build();
List servers = Lists.newArrayList(server);
ELBJob job = osv3().loadBalancer().servers().create(listenerId, servers);
assertTrue("2c9eb2c05cbc6a07015cd8c817925b98".equals(job.getJobId()));
}
public void testDeleteServer() throws IOException {
respondWith(JSON_SERVER_JOB);
String listenerId = "3a9fe2c9703c43e1ab761552a022c11e";
String serverId = "b235e7d0-8f6d-4777-b9ea-1b1596241996";
ELBJob job = osv3().loadBalancer().servers().delete(listenerId, Lists.newArrayList(serverId));
assertTrue("2c9eb2c05cbc6a07015cd8c817925b98".equals(job.getJobId()));
}
public void testListServer() throws IOException {
respondWith(JSON_SERVER_LIST);
respondWith(JSON_SERVER_LIST2);
String listenerId = "3a9fe2c9703c43e1ab761552a022c11e";
Server[] all = osv3().loadBalancer().servers().list(listenerId);
assertTrue(all.length == 2);
ELBServerListOptions options = ELBServerListOptions.create().healthStatus(HealthStatus.NORMAL);
Server[] list = osv3().loadBalancer().servers().list(listenerId, options);
if (list != null) {
for (Server server : list) {
assertTrue(HealthStatus.NORMAL.name().equalsIgnoreCase(server.getHealthStatus()));
}
}
}
@Override
protected Service service() {
return Service.LOAD_BALANCER;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy