/common/trmk/src/test/java/org/jclouds/trmk/vcloud_0_8/binders/BindAddNodeServiceToXmlPayloadTest.java
https://github.com/regularfry/jclouds · Java · 86 lines · 52 code · 11 blank · 23 comment · 0 complexity · d82e4225739a9e19d07675351178b82f MD5 · raw file
- /**
- * 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.trmk.vcloud_0_8.binders;
- import static org.jclouds.trmk.vcloud_0_8.reference.TerremarkConstants.PROPERTY_TERREMARK_EXTENSION_NS;
- import static org.testng.Assert.assertEquals;
- import java.io.IOException;
- import java.io.InputStream;
- import java.net.URI;
- import java.util.Map;
- import javax.inject.Named;
- import javax.inject.Singleton;
- import org.jclouds.http.HttpRequest;
- import org.jclouds.trmk.vcloud_0_8.binders.BindAddNodeServiceToXmlPayload;
- import org.jclouds.util.Strings2;
- import org.testng.annotations.Test;
- import com.google.common.collect.Maps;
- import com.google.inject.AbstractModule;
- import com.google.inject.Guice;
- import com.google.inject.Injector;
- import com.google.inject.Provides;
- import com.google.inject.name.Names;
- /**
- * Tests behavior of {@code BindAddNodeServiceToXmlPayload}
- *
- * @author Adrian Cole
- */
- @Test(groups = "unit")
- public class BindAddNodeServiceToXmlPayloadTest {
- Injector injector = Guice.createInjector(new AbstractModule() {
- @Override
- protected void configure() {
- bindConstant().annotatedWith(Names.named(PROPERTY_TERREMARK_EXTENSION_NS)).to(
- "urn:tmrk:vCloudExpressExtensions-1.6");
- }
- @SuppressWarnings("unused")
- @Singleton
- @Provides
- @Named("CreateNodeService")
- String provideInstantiateVAppTemplateParams() throws IOException {
- InputStream is = getClass().getResourceAsStream("/CreateNodeService.xml");
- return Strings2.toStringAndClose(is);
- }
- });
- public void testApplyInputStream() throws IOException {
- String expected = Strings2.toStringAndClose(getClass().getResourceAsStream(
- "/CreateNodeService-test.xml"));
- HttpRequest request = new HttpRequest("GET", URI.create("http://test"));
- BindAddNodeServiceToXmlPayload binder = injector
- .getInstance(BindAddNodeServiceToXmlPayload.class);
- Map<String, String> map = Maps.newHashMap();
- map.put("name", "Node for Jim");
- map.put("ipAddress", "172.16.20.3");
- map.put("port", "80");
- map.put("enabled", "false");
- map.put("description", "Some test node");
- binder.bindToRequest(request, map);
- assertEquals(request.getPayload().getRawContent(), expected);
- }
- }