/**
* Licensed to jclouds, Inc. (jclouds) under one or more
* contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. jclouds licenses this file
* to you 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 org.jclouds.rackspace.cloudloadbalancers.v1.features;
import static org.jclouds.rackspace.cloudloadbalancers.v1.predicates.LoadBalancerPredicates.awaitAvailable;
import static org.jclouds.rackspace.cloudloadbalancers.v1.predicates.LoadBalancerPredicates.awaitDeleted;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;
import org.jclouds.rackspace.cloudloadbalancers.v1.domain.LoadBalancer;
import org.jclouds.rackspace.cloudloadbalancers.v1.domain.CreateLoadBalancer;
import org.jclouds.rackspace.cloudloadbalancers.v1.domain.AddNode;
import org.jclouds.rackspace.cloudloadbalancers.v1.domain.VirtualIP.Type;
import org.jclouds.rackspace.cloudloadbalancers.v1.internal.BaseCloudLoadBalancersApiLiveTest;
import org.testng.annotations.AfterGroups;
import org.testng.annotations.BeforeGroups;
import org.testng.annotations.Test;
import com.google.common.collect.Iterables;
/**
* @author Everett Toews
*/
@Test(groups = "live", singleThreaded = true, testName = "ErrorPageApiLiveTest")
public class ErrorPageApiLiveTest extends BaseCloudLoadBalancersApiLiveTest {
private LoadBalancer lb;
private String zone;
private String contentExpected;
private String contentEscaped;
@Override
@BeforeGroups(groups = { "live" })
public void setup() {
super.setup();
contentExpected = ErrorPageApiExpectTest.getContentExpected();
contentEscaped = ErrorPageApiExpectTest.getContentEscaped();
}
public void testCreateLoadBalancer() {
AddNode addNode = AddNode.builder().address("192.168.1.1").port(8080).build();
CreateLoadBalancer createLB = CreateLoadBalancer.builder()
.name(prefix+"-jclouds").protocol("HTTP").port(80).virtualIPType(Type.PUBLIC).node(addNode).build();
zone = Iterables.getFirst(api.getConfiguredZones(), null);
lb = api.getLoadBalancerApiForZone(zone).create(createLB);
assertTrue(awaitAvailable(api.getLoadBalancerApiForZone(zone)).apply(lb));
}
@Test(dependsOnMethods = "testCreateLoadBalancer")
public void testCreateAndGetErrorPage() throws Exception {
api.getErrorPageApiForZoneAndLoadBalancer(zone, lb.getId()).create(contentEscaped);
assertTrue(awaitAvailable(api.getLoadBalancerApiForZone(zone)).apply(lb));
String content = api.getErrorPageApiForZoneAndLoadBalancer(zone, lb.getId()).get();
assertEquals(content, contentExpected);
}
@Test(dependsOnMethods = "testCreateAndGetErrorPage")
public void testRemoveAndGetErrorPage() throws Exception {
assertTrue(api.getErrorPageApiForZoneAndLoadBalancer(zone, lb.getId()).delete());
assertTrue(awaitAvailable(api.getLoadBalancerApiForZone(zone)).apply(lb));
String content = api.getErrorPageApiForZoneAndLoadBalancer(zone, lb.getId()).get();
assertTrue(content.contains("Service Unavailable"));
}
@Override
@AfterGroups(groups = "live")
protected void tearDown() {
assertTrue(awaitAvailable(api.getLoadBalancerApiForZone(zone)).apply(lb));
api.getLoadBalancerApiForZone(zone).delete(lb.getId());
assertTrue(awaitDeleted(api.getLoadBalancerApiForZone(zone)).apply(lb));
super.tearDown();
}
}