Repository :
http://git.fedorahosted.org/cgit/copr.git
On branch : master
---------------------------------------------------------------
commit 5337be1894c1de9c985ee410059cd680f03cb19e
Author: Mikolaj Izdebski <mizdebsk(a)redhat.com>
Date: Tue Sep 16 08:32:54 2014 +0200
[java] Implement project detail API call
---------------------------------------------------------------
.../org/fedoraproject/copr/client/CoprSession.java | 3 +
.../client/{ProjectId.java => DetailRequest.java} | 12 ++-
...PlaygroundListResult.java => DetailResult.java} | 13 ++-
.../fedoraproject/copr/client/YumRepository.java | 38 ++++++
.../copr/client/impl/DefaultCoprSession.java | 10 ++
.../copr/client/impl/DefaultDetailResult.java | 80 +++++++++++++
.../copr/client/impl/DetailCommand.java | 77 +++++++++++++
.../fedoraproject/copr/client/impl/DetailTest.java | 121 ++++++++++++++++++++
java/copr-impl/src/test/resources/detail1.json | 15 +++
9 files changed, 366 insertions(+), 3 deletions(-)
diff --git a/java/copr-api/src/main/java/org/fedoraproject/copr/client/CoprSession.java
b/java/copr-api/src/main/java/org/fedoraproject/copr/client/CoprSession.java
index 83bfbe2..3346a3d 100644
--- a/java/copr-api/src/main/java/org/fedoraproject/copr/client/CoprSession.java
+++ b/java/copr-api/src/main/java/org/fedoraproject/copr/client/CoprSession.java
@@ -27,6 +27,9 @@ public interface CoprSession
PlaygroundListResult playgroundList( PlaygroundListRequest request )
throws CoprException;
+ DetailResult detail( DetailRequest request )
+ throws CoprException;
+
BuildResult build( BuildRequest request )
throws CoprException;
diff --git a/java/copr-api/src/main/java/org/fedoraproject/copr/client/ProjectId.java
b/java/copr-api/src/main/java/org/fedoraproject/copr/client/DetailRequest.java
similarity index 83%
copy from java/copr-api/src/main/java/org/fedoraproject/copr/client/ProjectId.java
copy to java/copr-api/src/main/java/org/fedoraproject/copr/client/DetailRequest.java
index a7d8a35..652e28a 100644
--- a/java/copr-api/src/main/java/org/fedoraproject/copr/client/ProjectId.java
+++ b/java/copr-api/src/main/java/org/fedoraproject/copr/client/DetailRequest.java
@@ -18,12 +18,22 @@ package org.fedoraproject.copr.client;
/**
* @author Mikolaj Izdebski
*/
-public class ProjectId
+public class DetailRequest
{
private String userName;
private String projectName;
+ public DetailRequest()
+ {
+ }
+
+ public DetailRequest( String userName, String projectName )
+ {
+ this.userName = userName;
+ this.projectName = projectName;
+ }
+
public String getUserName()
{
return userName;
diff --git
a/java/copr-api/src/main/java/org/fedoraproject/copr/client/PlaygroundListResult.java
b/java/copr-api/src/main/java/org/fedoraproject/copr/client/DetailResult.java
similarity index 69%
copy from
java/copr-api/src/main/java/org/fedoraproject/copr/client/PlaygroundListResult.java
copy to java/copr-api/src/main/java/org/fedoraproject/copr/client/DetailResult.java
index 630214d..22cfecd 100644
--- a/java/copr-api/src/main/java/org/fedoraproject/copr/client/PlaygroundListResult.java
+++ b/java/copr-api/src/main/java/org/fedoraproject/copr/client/DetailResult.java
@@ -15,12 +15,21 @@
*/
package org.fedoraproject.copr.client;
+import java.util.Date;
import java.util.List;
/**
* @author Mikolaj Izdebski
*/
-public interface PlaygroundListResult
+public interface DetailResult
{
- List<ProjectId> getProjects();
+ public abstract Date getLastModified();
+
+ public abstract List<YumRepository> getYumRepositories();
+
+ public abstract String getAdditionalRepos();
+
+ public abstract String getInstructions();
+
+ public abstract String getDescription();
}
diff --git a/java/copr-api/src/main/java/org/fedoraproject/copr/client/YumRepository.java
b/java/copr-api/src/main/java/org/fedoraproject/copr/client/YumRepository.java
new file mode 100644
index 0000000..44aacf3
--- /dev/null
+++ b/java/copr-api/src/main/java/org/fedoraproject/copr/client/YumRepository.java
@@ -0,0 +1,38 @@
+package org.fedoraproject.copr.client;
+
+public class YumRepository
+{
+ private String name;
+
+ private String baseUrl;
+
+ public YumRepository()
+ {
+ }
+
+ public YumRepository( String name, String baseUrl )
+ {
+ this.name = name;
+ this.baseUrl = baseUrl;
+ }
+
+ public String getName()
+ {
+ return name;
+ }
+
+ public void setName( String name )
+ {
+ this.name = name;
+ }
+
+ public String getBaseUrl()
+ {
+ return baseUrl;
+ }
+
+ public void setBaseUrl( String baseUrl )
+ {
+ this.baseUrl = baseUrl;
+ }
+}
diff --git
a/java/copr-impl/src/main/java/org/fedoraproject/copr/client/impl/DefaultCoprSession.java
b/java/copr-impl/src/main/java/org/fedoraproject/copr/client/impl/DefaultCoprSession.java
index 4437863..59ec039 100644
---
a/java/copr-impl/src/main/java/org/fedoraproject/copr/client/impl/DefaultCoprSession.java
+++
b/java/copr-impl/src/main/java/org/fedoraproject/copr/client/impl/DefaultCoprSession.java
@@ -22,6 +22,8 @@ import org.fedoraproject.copr.client.BuildResult;
import org.fedoraproject.copr.client.CoprConfiguration;
import org.fedoraproject.copr.client.CoprException;
import org.fedoraproject.copr.client.CoprSession;
+import org.fedoraproject.copr.client.DetailRequest;
+import org.fedoraproject.copr.client.DetailResult;
import org.fedoraproject.copr.client.ListRequest;
import org.fedoraproject.copr.client.ListResult;
import org.fedoraproject.copr.client.PlaygroundListRequest;
@@ -76,6 +78,14 @@ public class DefaultCoprSession
}
@Override
+ public DetailResult detail( DetailRequest request )
+ throws CoprException
+ {
+ DetailCommand command = new DetailCommand( request );
+ return command.execute( this );
+ }
+
+ @Override
public BuildResult build( BuildRequest request )
throws CoprException
{
diff --git
a/java/copr-impl/src/main/java/org/fedoraproject/copr/client/impl/DefaultDetailResult.java
b/java/copr-impl/src/main/java/org/fedoraproject/copr/client/impl/DefaultDetailResult.java
new file mode 100644
index 0000000..7aa4498
--- /dev/null
+++
b/java/copr-impl/src/main/java/org/fedoraproject/copr/client/impl/DefaultDetailResult.java
@@ -0,0 +1,80 @@
+/*-
+ * Copyright (c) 2014 Red Hat, Inc.
+ *
+ * Licensed 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.fedoraproject.copr.client.impl;
+
+import java.util.Collections;
+import java.util.Date;
+import java.util.List;
+
+import org.fedoraproject.copr.client.DetailResult;
+import org.fedoraproject.copr.client.YumRepository;
+
+/**
+ * @author Mikolaj Izdebski
+ */
+public class DefaultDetailResult
+ implements DetailResult
+{
+ private final String description;
+
+ private final String instructions;
+
+ private final String additionalRepos;
+
+ private final List<YumRepository> yumRepositories;
+
+ private final Date lastModified;
+
+ public DefaultDetailResult( String description, String instructions, String
additionalRepos,
+ List<YumRepository> yumRepositories, long
lastModified )
+ {
+ this.description = description;
+ this.instructions = instructions;
+ this.additionalRepos = additionalRepos;
+ this.yumRepositories = Collections.unmodifiableList( yumRepositories );
+ this.lastModified = new Date( lastModified );
+ }
+
+ @Override
+ public String getDescription()
+ {
+ return description;
+ }
+
+ @Override
+ public String getInstructions()
+ {
+ return instructions;
+ }
+
+ @Override
+ public String getAdditionalRepos()
+ {
+ return additionalRepos;
+ }
+
+ @Override
+ public List<YumRepository> getYumRepositories()
+ {
+ return yumRepositories;
+ }
+
+ @Override
+ public Date getLastModified()
+ {
+ return lastModified;
+ }
+}
diff --git
a/java/copr-impl/src/main/java/org/fedoraproject/copr/client/impl/DetailCommand.java
b/java/copr-impl/src/main/java/org/fedoraproject/copr/client/impl/DetailCommand.java
new file mode 100644
index 0000000..73b0a7f
--- /dev/null
+++ b/java/copr-impl/src/main/java/org/fedoraproject/copr/client/impl/DetailCommand.java
@@ -0,0 +1,77 @@
+/*-
+ * Copyright (c) 2014 Red Hat, Inc.
+ *
+ * Licensed 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.fedoraproject.copr.client.impl;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+
+import org.fedoraproject.copr.client.DetailRequest;
+import org.fedoraproject.copr.client.DetailResult;
+import org.fedoraproject.copr.client.YumRepository;
+
+import com.google.gson.JsonElement;
+import com.google.gson.JsonObject;
+
+/**
+ * @author Mikolaj Izdebski
+ */
+public class DetailCommand
+ extends RpcCommand<DetailResult>
+{
+ private final DetailRequest request;
+
+ public DetailCommand( DetailRequest request )
+ {
+ this.request = request;
+ }
+
+ @Override
+ protected String getCommandUrl()
+ {
+ return "/api/coprs/" + request.getUserName() + "/" +
request.getProjectName() + "/detail/";
+ }
+
+ @Override
+ protected Map<String, String> getExtraArguments()
+ {
+ return null;
+ }
+
+ @Override
+ protected DetailResult parseResponse( JsonObject response )
+ {
+ JsonObject detail = response.get( "detail" ).getAsJsonObject();
+
+ String additionalRepos = detail.get( "additional_repos"
).getAsString();
+ String description = detail.get( "description" ).getAsString();
+ String instructions = detail.get( "instructions" ).getAsString();
+ long lastModified = detail.get( "last_modified" ).getAsLong();
+
+ JsonObject repos = detail.get( "yum_repos" ).getAsJsonObject();
+ List<YumRepository> yumRepos = new ArrayList<>();
+ for ( Entry<String, JsonElement> entry : repos.entrySet() )
+ {
+ String name = entry.getKey();
+ String baseUrl = entry.getValue().getAsString();
+ YumRepository repo = new YumRepository( name, baseUrl );
+ yumRepos.add( repo );
+ }
+
+ return new DefaultDetailResult( description, instructions, additionalRepos,
yumRepos, lastModified );
+ }
+}
diff --git
a/java/copr-impl/src/test/java/org/fedoraproject/copr/client/impl/DetailTest.java
b/java/copr-impl/src/test/java/org/fedoraproject/copr/client/impl/DetailTest.java
new file mode 100644
index 0000000..a669e90
--- /dev/null
+++ b/java/copr-impl/src/test/java/org/fedoraproject/copr/client/impl/DetailTest.java
@@ -0,0 +1,121 @@
+/*-
+ * Copyright (c) 2014 Red Hat, Inc.
+ *
+ * Licensed 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.fedoraproject.copr.client.impl;
+
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.replay;
+import static org.easymock.EasyMock.verify;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.util.Date;
+import java.util.Iterator;
+
+import org.easymock.EasyMockRunner;
+import org.fedoraproject.copr.client.CoprException;
+import org.fedoraproject.copr.client.DetailRequest;
+import org.fedoraproject.copr.client.DetailResult;
+import org.fedoraproject.copr.client.YumRepository;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+@RunWith( EasyMockRunner.class )
+public class DetailTest
+ extends RpcTest
+{
+ @Test
+ public void testApiFailure()
+ throws Exception
+ {
+ expect( mock.get( "/api/coprs/mizdebsk/override/detail/" ) ).andReturn(
"fail" );
+ replay( mock );
+
+ DetailRequest request = new DetailRequest( "mizdebsk",
"override" );
+
+ try
+ {
+ session.detail( request );
+ fail();
+ }
+ catch ( CoprException e )
+ {
+ verify( mock );
+ assertEquals( 1, server.getAcceptedConnectionCount() );
+ }
+ }
+
+ @Test
+ public void test404()
+ throws Exception
+ {
+ expect( mock.get( "/api/coprs/mizdebsk/override/detail/" ) ).andReturn(
null );
+ replay( mock );
+
+ DetailRequest request = new DetailRequest( "mizdebsk",
"override" );
+
+ try
+ {
+ session.detail( request );
+ fail();
+ }
+ catch ( CoprException e )
+ {
+ verify( mock );
+ assertEquals( 1, server.getAcceptedConnectionCount() );
+
+ assertTrue( e.getMessage().contains( "404 Not Found" ) );
+ }
+ }
+
+ @Test
+ public void testSingleRepo()
+ throws Exception
+ {
+ expect( mock.get( "/api/coprs/mizdebsk/override/detail/" ) ).andReturn(
"detail1" );
+ replay( mock );
+
+ DetailRequest request = new DetailRequest( "mizdebsk",
"override" );
+ DetailResult result = session.detail( request );
+
+ verify( mock );
+ assertEquals( 1, server.getAcceptedConnectionCount() );
+
+ assertNotNull( result );
+ assertEquals( "Fixed or tweaked versions of some Fedora packages, for
personal use.", result.getDescription() );
+ assertEquals( "Nothing complicated, really...",
result.getInstructions() );
+ assertEquals( "", result.getAdditionalRepos() );
+ assertEquals( new Date( 1407916203 ), result.getLastModified() );
+
+ Iterator<YumRepository> it = result.getYumRepositories().iterator();
+ assertTrue( it.hasNext() );
+ YumRepository repo1 = it.next();
+ assertEquals( "fedora-20-x86_64", repo1.getName() );
+ assertEquals(
"http://copr-be.cloud.fedoraproject.org/results/mizdebsk/override/fedora-20-x86_64/",
+ repo1.getBaseUrl() );
+ YumRepository repo2 = it.next();
+ assertEquals( "fedora-21-x86_64", repo2.getName() );
+ assertEquals(
"http://copr-be.cloud.fedoraproject.org/results/mizdebsk/override/fedora-21-x86_64/",
+ repo2.getBaseUrl() );
+ YumRepository repo3 = it.next();
+ assertEquals( "fedora-rawhide-x86_64", repo3.getName() );
+ assertEquals(
"http://copr-be.cloud.fedoraproject.org/results/mizdebsk/override/fedora-rawhide-x86_64/",
+ repo3.getBaseUrl() );
+ assertFalse( it.hasNext() );
+ }
+}
diff --git a/java/copr-impl/src/test/resources/detail1.json
b/java/copr-impl/src/test/resources/detail1.json
new file mode 100644
index 0000000..1e8f3a5
--- /dev/null
+++ b/java/copr-impl/src/test/resources/detail1.json
@@ -0,0 +1,15 @@
+{
+ "detail": {
+ "additional_repos": "",
+ "description": "Fixed or tweaked versions of some Fedora packages, for
personal use.",
+ "instructions": "Nothing complicated, really...",
+ "last_modified": 1407916203,
+ "name": "override",
+ "yum_repos": {
+ "fedora-20-x86_64":
"http://copr-be.cloud.fedoraproject.org/results/mizdebsk/override/fedora-20-x86_64/",
+ "fedora-21-x86_64":
"http://copr-be.cloud.fedoraproject.org/results/mizdebsk/override/fedora-21-x86_64/",
+ "fedora-rawhide-x86_64":
"http://copr-be.cloud.fedoraproject.org/results/mizdebsk/override/fedora-rawhide-x86_64/"
+ }
+ },
+ "output": "ok"
+}