PageRenderTime 30ms CodeModel.GetById 13ms app.highlight 14ms RepoModel.GetById 1ms app.codeStats 0ms

/apis/vcloud/src/test/java/org/jclouds/vcloud/xml/NetworkConnectionSectionHandlerTest.java

https://github.com/regularfry/jclouds
Java | 65 lines | 36 code | 6 blank | 23 comment | 0 complexity | 9392c064bbfa7cd64c8254ecea07ddf9 MD5 | raw file
 1/**
 2 * Licensed to jclouds, Inc. (jclouds) under one or more
 3 * contributor license agreements.  See the NOTICE file
 4 * distributed with this work for additional information
 5 * regarding copyright ownership.  jclouds licenses this file
 6 * to you under the Apache License, Version 2.0 (the
 7 * "License"); you may not use this file except in compliance
 8 * with the License.  You may obtain a copy of the License at
 9 *
10 *   http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied.  See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19package org.jclouds.vcloud.xml;
20
21import static org.testng.Assert.assertEquals;
22
23import java.io.InputStream;
24import java.net.URI;
25
26import org.jclouds.http.functions.ParseSax;
27import org.jclouds.http.functions.ParseSax.Factory;
28import org.jclouds.http.functions.config.SaxParserModule;
29import org.jclouds.vcloud.VCloudMediaType;
30import org.jclouds.vcloud.domain.NetworkConnectionSection;
31import org.jclouds.vcloud.domain.internal.ReferenceTypeImpl;
32import org.testng.annotations.Test;
33
34import com.google.common.collect.Iterables;
35import com.google.inject.Guice;
36import com.google.inject.Injector;
37
38/**
39 * Tests behavior of {@code NetworkConnectionSectionHandler}
40 * 
41 * @author Adrian Cole
42 */
43@Test(groups = "unit")
44public class NetworkConnectionSectionHandlerTest {
45   public void testVCloud1_0() {
46      InputStream is = getClass().getResourceAsStream("/networkconnectionsection.xml");
47      Injector injector = Guice.createInjector(new SaxParserModule());
48      Factory factory = injector.getInstance(ParseSax.Factory.class);
49      NetworkConnectionSection result = factory.create(injector.getInstance(NetworkConnectionSectionHandler.class))
50               .parse(is);
51      checkNetworkConnectionSection(result);
52   }
53
54   @Test(enabled = false)
55   static void checkNetworkConnectionSection(NetworkConnectionSection result) {
56      assertEquals(result.getHref(), URI
57               .create("https://vcenterprise.bluelock.com/api/v1.0/vApp/vm-2087535248/networkConnectionSection/"));
58      assertEquals(result.getType(), VCloudMediaType.NETWORKCONNECTIONSECTION_XML);
59      assertEquals(result.getInfo(), "Specifies the available VM network connections");
60      assertEquals(result.getPrimaryNetworkConnectionIndex(), new Integer(0));
61      assertEquals(result.getEdit(), new ReferenceTypeImpl(null, VCloudMediaType.NETWORKCONNECTIONSECTION_XML, URI
62               .create("https://vcenterprise.bluelock.com/api/v1.0/vApp/vm-2087535248/networkConnectionSection/")));
63      NetworkConnectionHandlerTest.checkNetworkConnection(Iterables.getOnlyElement(result.getConnections()));
64   }
65}