Issue 695: Added test for BindSSHKeyToXmlPayload

This commit is contained in:
Jason King 2011-12-13 15:15:10 +00:00
parent ccaac6da5f
commit 7f71cb3896
3 changed files with 80 additions and 2 deletions

View File

@ -33,9 +33,8 @@ import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* TODO Tests
*
* @author Jason King
*
*/
@Singleton
public class BindSSHKeyToXmlPayload implements Binder {

View File

@ -0,0 +1,75 @@
/**
* 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.tmrk.enterprisecloud.binders;
import com.google.inject.AbstractModule;
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.Provides;
import org.jclouds.http.HttpRequest;
import org.jclouds.tmrk.enterprisecloud.domain.keys.SSHKey;
import org.jclouds.util.Strings2;
import org.testng.annotations.Test;
import javax.inject.Named;
import javax.inject.Singleton;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import static org.testng.Assert.assertEquals;
/**
* Tests behavior of {@code BindSSHKeyToXmlPayloadTest}
* @author Jason King
*/
@Test(groups = "unit", testName = "BindSSHKeyToXmlPayloadTest")
public class BindSSHKeyToXmlPayloadTest {
Injector injector = Guice.createInjector(new AbstractModule() {
@Override
protected void configure() {
}
@SuppressWarnings("unused")
@Singleton
@Provides
@Named("EditSSHKey")
String provideInstantiateVAppTemplateParams() throws IOException {
InputStream is = getClass().getResourceAsStream("/EditSSHKey.xml");
return Strings2.toStringAndClose(is);
}
});
public void testApplyInputStream() throws IOException {
String expected = Strings2.toStringAndClose(getClass().getResourceAsStream(
"/EditSSHKey-test.xml"));
HttpRequest request = new HttpRequest("GET", URI.create("http://test"));
BindSSHKeyToXmlPayload binder = injector
.getInstance(BindSSHKeyToXmlPayload.class);
SSHKey key = SSHKey.builder().type("application/vnd.tmrk.cloud.admin.sshKey")
.href(URI.create("/cloudapi/ecloud/admin/sshkeys/77"))
.name("newName")
.defaultKey(false).fingerPrint("123").build();
binder.bindToRequest(request, key);
assertEquals(request.getPayload().getRawContent(), expected);
}
}

View File

@ -0,0 +1,4 @@
<SshKey name="newName">
<Default>false</Default>
<FingerPrint>123</FingerPrint>
</SshKey>