Skip to content

Commit

Permalink
Fill out history and library clients a little more.
Browse files Browse the repository at this point in the history
  • Loading branch information
jmchilton committed Aug 20, 2012
1 parent 1c7c7f5 commit f301608
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 60 deletions.
26 changes: 22 additions & 4 deletions .classpath
Original file line number Diff line number Diff line change
@@ -1,8 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java"/>
<classpathentry kind="src" output="target/test-classes" path="src/test/java"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"/>
<classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,36 @@

import java.util.List;


import org.codehaus.jackson.type.TypeReference;

import com.sun.jersey.api.client.ClientResponse;

public class HistoryClient extends Client {

HistoryClient(GalaxyInstance galaxyInstance) {
super(galaxyInstance, "histories");
}

public ClientResponse create(final History history) {
return super.create(history);
public ClientResponse createRequest(final History history) {
return super.create(history);
}

public History create(final History history) {
return createRequest(history).getEntity(History.class);
}

public List<History> getHistories() {
final TypeReference<List<History>> typeReference = new TypeReference<List<History>>() {};
final TypeReference<List<History>> typeReference = new TypeReference<List<History>>() {
};
return get(typeReference);
}

public static class History extends GalaxyObject {
private String name;

public History() {
}

public History(final String name) {
this.setName(name);
}
Expand All @@ -39,25 +43,25 @@ public String getName() {
public void setName(String name) {
this.name = name;
}

}

public static class PersistedHistory extends History {
private String id;
private String url;

public String getId() {
return id;
}

public void setId(String id) {
this.id = id;
}

public String getUrl() {
return url;
}

public void setUrl(final String url) {
this.url = url;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,49 +8,67 @@
import com.sun.jersey.api.client.ClientResponse;

public class LibraryClient extends Client {

public LibraryClient(GalaxyInstance galaxyInstance) {
super(galaxyInstance, "libraries");
}

public ClientResponse create(final Library library) {
public ClientResponse createRequest(final Library library) {
return super.create(library);
}


public Library create(final Library library) {
return createRequest(library).getEntity(Library.class);
}

public List<Library> getLibraries() {
return get(new TypeReference<List<Library>>() {});
return get(new TypeReference<List<Library>>() {
});
}


public LibraryContent getRootFolder(final String libraryId) {
final List<LibraryContent> libraryContents = getLibraryContents(libraryId);
LibraryContent rootFolder = null;
for(final LibraryContent content : libraryContents) {
if("/".equals(content.getName())) {
rootFolder = content;
break;
}
}
return rootFolder;
}

public List<LibraryContent> getLibraryContents(final String libraryId) {
return get(getWebResource().path(libraryId).path("contents"), new TypeReference<List<LibraryContent>>() {});
return get(getWebResource().path(libraryId).path("contents"), new TypeReference<List<LibraryContent>>() {
});
}

public ClientResponse uploadFileFromUrl(final String libraryId, final FilesystemPathsLibraryUpload upload) {
return super.create(getWebResource().path(libraryId).path("contents"), upload);
}

public static class LibraryContent extends GalaxyObject {
private String name;
private String type;

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getType() {
return type;
}

public void setType(String type) {
this.type = type;
}

}

public static class Library extends GalaxyObject {
private String name = "";
private String description = "";
Expand All @@ -59,32 +77,32 @@ public static class Library extends GalaxyObject {
public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getDescription() {
return description;
}

public void setDescription(String description) {
this.description = description;
}

public String getSynopsis() {
return synopsis;
}

public void setSynopsis(String synopsis) {
this.synopsis = synopsis;
}

}

public static class FilesystemPathsLibraryUpload extends LibraryUpload {
private String fileUrl;

@JsonGetter("upload_option")
public String getUploadOption() {
return "upload_paths";
Expand All @@ -100,35 +118,35 @@ public void setFilesystemPaths(String fileUrl) {
}

}

public static class LibraryUpload extends GalaxyObject {
private String folderId;
private String libraryId;
private String fileType = "auto";
private String dbkey = "?";

@JsonGetter("folder_id")
public String getFolderId() {
return folderId;
}

public void setFolderId(String folderId) {
this.folderId = folderId;
}

@JsonGetter("file_type")
public String getFileType() {
return fileType;
}

public void setFileType(String fileType) {
this.fileType = fileType;
}

public String getDbkey() {
return dbkey;
}

public void setDbkey(String dbkey) {
this.dbkey = dbkey;
}
Expand All @@ -137,7 +155,7 @@ public void setDbkey(String dbkey) {
public String getCreateType() {
return "file";
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,18 @@
import com.sun.jersey.api.client.ClientResponse;

public class IntegrationTest {

@Test
public void checkHistories() {
final GalaxyInstance galaxyInstance = TestGalaxyInstance.get();
final HistoryClient historyClient = galaxyInstance.getHistoryClient();
final History history = new History();
final String testHistoryName = "testHistory" + UUID.randomUUID().toString();
history.setName(testHistoryName);
final ClientResponse response = historyClient.create(history);
final ClientResponse response = historyClient.createRequest(history);
Assert.assertTrue(response.getStatus() == 200, String.format("Expected 200: %d", response.getStatus()));

final Library persistedLibrary = response.getEntity(Library.class);
System.out.println(persistedLibrary.getId());
final List<History> histories = historyClient.getHistories();
boolean foundHistory = false;
for(final History returnedHistory : histories) {
Expand All @@ -33,19 +34,19 @@ public void checkHistories() {
}
Assert.assertTrue(foundHistory, "Could not find previously created test history.");
}

private void assert200(final ClientResponse clientResponse) {
Assert.assertTrue(clientResponse.getStatus() == 200, String.format("Expected 200 status code, got %d. %s", clientResponse.getStatus(), clientResponse.getEntity(String.class)));
Assert.assertTrue(clientResponse.getStatus() == 200,
String.format("Expected 200 status code, got %d. %s", clientResponse.getStatus(), clientResponse.getEntity(String.class)));
}



@Test
public void testLibraries() {
final GalaxyInstance galaxyInstance = TestGalaxyInstance.get();
final LibraryClient libraryClient = galaxyInstance.getLibraryClient();
final Library testLibrary = new Library();
testLibrary.setName("testLib" + UUID.randomUUID().toString());
final ClientResponse response = libraryClient.create(testLibrary);
final ClientResponse response = libraryClient.createRequest(testLibrary);
assert200(response);
final List<Library> libraries = libraryClient.getLibraries();
Library matchingLibrary = null;
Expand All @@ -63,11 +64,10 @@ public void testLibraries() {
upload.setFolderId(rootFolderId);
final ClientResponse uploadResponse = libraryClient.uploadFileFromUrl(matchingLibrary.getId(), upload);
assert200(uploadResponse);


//for(final LibraryContent content : contents) {
// System.out.println(content);
//}
// for(final LibraryContent content : contents) {
// System.out.println(content);
// }
}

}

0 comments on commit f301608

Please sign in to comment.