mirror of https://github.com/apache/jclouds.git
Adding a test to check for JCLOUDS-278
Contributed by Bill Branan.
This commit is contained in:
parent
bb3c9d2657
commit
b1c163636d
|
@ -0,0 +1,73 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF 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.openstack.swift.functions;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.reflect.Invokable;
|
||||
import com.google.gson.Gson;
|
||||
import org.jclouds.blobstore.domain.PageSet;
|
||||
import org.jclouds.json.internal.GsonWrapper;
|
||||
import org.jclouds.openstack.swift.domain.ObjectInfo;
|
||||
import org.jclouds.openstack.swift.options.ListContainerOptions;
|
||||
import org.jclouds.reflect.Invocation;
|
||||
import org.jclouds.rest.internal.GeneratedHttpRequest;
|
||||
import org.jclouds.util.Strings2;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import javax.ws.rs.core.NewCookie;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertNotNull;
|
||||
|
||||
/**
|
||||
* @author Bill Branan
|
||||
*/
|
||||
@Test(groups = "unit")
|
||||
public class ParseObjectInfoListFromJsonResponseTest {
|
||||
|
||||
@Test
|
||||
public void testNoUrlDecodingOfResponse() throws Exception {
|
||||
// '%x' is not a valid URL encoding
|
||||
String contentName = "swift-test-content-%x-1401395399020";
|
||||
|
||||
String jsonObjectList =
|
||||
"[{\"last_modified\": \"2014-05-29T20:30:03.845660\", " +
|
||||
"\"bytes\": 19, " +
|
||||
"\"name\": \"" + contentName + "\", " +
|
||||
"\"content_type\": \"application/unknown\"}]";
|
||||
|
||||
InputStream stream = Strings2.toInputStream(jsonObjectList);
|
||||
|
||||
ParseObjectInfoListFromJsonResponse parser =
|
||||
new ParseObjectInfoListFromJsonResponse(new GsonWrapper(new Gson()));
|
||||
|
||||
GeneratedHttpRequest.Builder builder = new GeneratedHttpRequest.Builder();
|
||||
builder.method("method")
|
||||
.endpoint("http://test.org/test")
|
||||
.invocation(Invocation.create(Invokable.from(Object.class.getMethod("toString", null)),
|
||||
ImmutableList.<Object>of("container-name", new ListContainerOptions[0])))
|
||||
.caller(null);
|
||||
|
||||
parser.setContext(builder.build());
|
||||
|
||||
ObjectInfo objectInfo = parser.apply(stream).iterator().next();
|
||||
assertEquals(objectInfo.getName(), contentName);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue