Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,16 @@
*/
public final class JiraServerInfo extends AbstractJiraServerInfo
{
private String version;
private String baseUrl;
private String buildDate;
private int buildNumber;
private final String version;

private final String baseUrl;

private final String buildDate;

private final int buildNumber;

private String edition;

private String serverTime;

public JiraServerInfo( String version, String baseUrl, String buildDate, int buildNumber )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,17 @@ public class JiraServerInfoConverter implements Converter<AbstractJiraServerInfo
@Override
public AbstractJiraServerInfo parse( Object object )
{
Map<String, Object> map = (Map) object;
Map<String, Object> map = (Map<String, Object>) object;
String version = (String) map.get( "version" );
String baseUrl = (String) map.get( "baseUrl" );
String buildDate = (String) map.get( "buildDate" );
String edition = (String) map.get( "edition" );
String serverTime = (String) map.get( "serverTime" );
int buildNumber = (Integer) map.get( "buildNumber" );

JiraServerInfo ret = new JiraServerInfo(version, baseUrl, buildDate, buildNumber);
ret.setEdition(edition);
ret.setServerTime(serverTime);
JiraServerInfo ret = new JiraServerInfo( version, baseUrl, buildDate, buildNumber );
ret.setEdition( edition );
ret.setServerTime( serverTime );
return ret;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
@Response
public class GetBuildResponse
{
@DataIndex(0)
@DataIndex( 0 )
private KojiBuildInfo buildInfo;

public KojiBuildInfo getBuildInfo()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public class KojiBuildInfo

public KojiBuildInfo() {}

public KojiBuildInfo(int id, int packageId, String name, String version, String release)
public KojiBuildInfo( int id, int packageId, String name, String version, String release )
{
setId( id );
setPackageId( packageId );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public class KojiTagInfo

public KojiTagInfo(){}

public KojiTagInfo( String name)
public KojiTagInfo( String name )
{
this.name = name;
}
Expand Down Expand Up @@ -84,7 +84,7 @@ public List<String> getArches()

public boolean isLocked()
{
return locked;
return locked != null && locked;
}

public boolean getMavenSupport()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public void setValue( double value )
this.value = value;
}

@DataIndex(0)
@DataIndex( 0 )
private double value;

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@
*/
public class Constants
{
private Constants()
{
throw new UnsupportedOperationException( "This is a utility class and cannot be instantiated" );
}

public static final String NAME = "name";

public static final String VERSION = "version";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
@Response
public class GetBuildDescriptionResponse
{
@DataIndex(0)
@DataIndex( 0 )
private BuildDescription value;

public BuildDescription getValue()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import org.commonjava.rwx.test.generated.Test_Registry;
import org.junit.BeforeClass;

import javax.xml.stream.XMLStreamException;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
Expand All @@ -41,25 +40,25 @@ public static void register()
Registry.setInstance( new Test_Registry() );
}

protected InputStream getXMLStream( final String name ) throws IOException, XMLStreamException
protected InputStream getXMLStream( final String name )
{
return Thread.currentThread().getContextClassLoader().getResourceAsStream( DOC_PATH + name + ".xml" );
}

protected String getXMLString( final String name ) throws IOException, XMLStreamException
protected String getXMLString( final String name ) throws IOException
{
return IOUtils.toString( new InputStreamReader( getXMLStream( name ) ));
}

// Comparing XML string is a bad idea. But we need it in some cases, e.g., kojiListBuildsResponseNIL

protected String getXMLStringIgnoreFormat( final String name ) throws IOException, XMLStreamException
protected String getXMLStringIgnoreFormat( final String name ) throws IOException
{
final BufferedReader reader = new BufferedReader( new InputStreamReader( getXMLStream( name ) ) );
final StringWriter writer = new StringWriter();
final PrintWriter pWriter = new PrintWriter( writer );

String line = null;
String line;
while ( ( line = reader.readLine() ) != null )
{
pWriter.print( line.trim() );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import org.junit.Test;

import java.io.ByteArrayInputStream;
import java.util.List;

import static junit.framework.TestCase.assertEquals;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@
package org.commonjava.rwx.test.jira;

import org.commonjava.rwx.api.RWXMapper;
import org.commonjava.rwx.core.Registry;
import org.commonjava.rwx.test.AbstractTest;
import org.commonjava.rwx.test.generated.Test_Registry;
import org.junit.BeforeClass;
import org.junit.Test;

import java.io.ByteArrayInputStream;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

import org.commonjava.rwx.api.RWXMapper;
import org.commonjava.rwx.core.Registry;
import org.commonjava.rwx.error.XmlRpcException;
import org.commonjava.rwx.test.AbstractTest;
import org.junit.Test;

Expand Down Expand Up @@ -51,7 +50,7 @@ public void multiCallRequest_renderTest_0() throws Exception

Object renderedKojiNVR = Registry.getInstance().renderTo( kojiNVR );

List params = new ArrayList<>( );
List<Object> params = new ArrayList<>( );
params.add( renderedKojiNVR );
multiCallObj.setParams( params );

Expand All @@ -69,7 +68,7 @@ public void multiCallRequest_renderTest() throws Exception
List<MultiCallObj> multiObjs = new ArrayList<>( );

MultiCallObj callObj_1 = new MultiCallObj( "getBuild" );
List params = new ArrayList<>( );
List<Object> params = new ArrayList<>( );
params.add( "org.dashbuilder-dashbuilder-parent-metadata-0.4.0.Final-1" );
callObj_1.setParams( params );
multiObjs.add( callObj_1 );
Expand Down Expand Up @@ -143,7 +142,7 @@ public void roundTrip_MultiCallResponse() throws Exception
assertMultiCallResponse( rounded );
}

private void assertMultiCallResponse( MultiCallResponse response ) throws XmlRpcException
private void assertMultiCallResponse( MultiCallResponse response )
{
List<MultiCallValueObj> valueObjs = response.getValueObjs();

Expand All @@ -167,15 +166,15 @@ private void assertMultiCallResponse( MultiCallResponse response ) throws XmlRpc
assertEquals( "org.dashbuilder-dashbuilder-parent-metadata", kojiBuildInfo.getPackageName() );

// if we do not know the type, access Map directly
Map<String, Object> data1Map = (Map) data1;
Map<String, Object> data1Map = (Map<String, Object>) data1;
assertEquals( 48475, data1Map.get( "package_id" ) );
assertEquals( 513598, data1Map.get( "build_id" ) );
assertEquals( "org.dashbuilder-dashbuilder-parent-metadata", data1Map.get( "package_name" ) );


// b. verify response from listTags call

List<Object> data2List = (List) data2;
List<Object> data2List = (List<Object>) data2;
assertEquals( 4, data2List.size() );

// if we know the type (KojiTagInfo) in the list, parse the element to it
Expand All @@ -186,7 +185,7 @@ private void assertMultiCallResponse( MultiCallResponse response ) throws XmlRpc
// if we do not know the type, access List directly
Object data2_1 = data2List.get( 0 );
assertTrue( data2_1 instanceof Map );
Map<String, Object> data2_1Map = (Map) data2_1;
Map<String, Object> data2_1Map = (Map<String, Object>) data2_1;
assertEquals( "jb-bxms-6.3-candidate", data2_1Map.get( "name" ) );
assertEquals( 8829, data2_1Map.get( "id" ) );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@

import org.commonjava.rwx.api.RWXMapper;
import org.commonjava.rwx.test.AbstractTest;
import org.commonjava.rwx.test.simple.RequestWithOneParam;
import org.junit.Test;

import java.io.ByteArrayInputStream;
import java.util.List;

import static junit.framework.TestCase.assertEquals;
import static junit.framework.TestCase.assertNull;
import static junit.framework.TestCase.assertTrue;

/**
* Created by ruhan on 8/2/17.
Expand Down Expand Up @@ -113,7 +114,7 @@ private void assertGetBuildResponse( GetBuildResponse response )
assertEquals( "org.dashbuilder-dashbuilder-parent-metadata", buildInfo.getName() );
assertEquals( "1", buildInfo.getRelease() );
assertEquals( "0.4.0.Final_10", buildInfo.getVersion() );
assertEquals( null, buildInfo.getExtra() );
assertNull( buildInfo.getExtra() );
}

@Test
Expand All @@ -123,7 +124,7 @@ public void roundTrip_ListBuildResponseNIL() throws Exception
ListBuildResponse parsed =
new RWXMapper().parse( new ByteArrayInputStream( source.getBytes() ), ListBuildResponse.class );

assertEquals( null, parsed.getBuilds() );
assertNull( parsed.getBuilds() );

String rendered = new RWXMapper().render( parsed );

Expand Down Expand Up @@ -155,11 +156,11 @@ private void assertListTagsResponse( ListTagsResponse response )
for ( KojiTagInfo tag : tags )
{
assertEquals( Boolean.FALSE, tag.getLocked() );
assertEquals( true, tag.getMavenSupport() );
assertEquals( true, tag.getMavenIncludeAll() );
assertEquals( null, tag.getPermission() );
assertEquals( null, tag.getPermissionId() );
assertEquals( null, tag.getArches() );
assertTrue( tag.getMavenSupport() );
assertTrue( tag.getMavenIncludeAll() );
assertNull( tag.getPermission() );
assertNull( tag.getPermissionId() );
assertNull( tag.getArches() );
}

KojiTagInfo tag0 = tags.get( 0 );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@
package org.commonjava.rwx.test.simple;

import org.commonjava.rwx.api.RWXMapper;
import org.commonjava.rwx.core.Registry;
import org.commonjava.rwx.test.AbstractTest;
import org.junit.BeforeClass;
import org.junit.Test;

import java.io.ByteArrayInputStream;
Expand Down Expand Up @@ -56,7 +54,7 @@ public void requestWithOneParamTest() throws Exception
public void roundTrip_RequestWithOneArrayParamTest() throws Exception
{
RequestWithOneArrayParam requst = new RequestWithOneArrayParam();
List<String> array = Arrays.asList( new String[] { "test1", "test2" } );
List<String> array = Arrays.asList( "test1", "test2" );
requst.setArray( array );
String request = new RWXMapper().render( requst );
String expected = getXMLStringIgnoreFormat( "requestWithOneArrayParam" );
Expand All @@ -75,5 +73,4 @@ public void simpleResponseTest() throws Exception
SimpleResponse response = new RWXMapper().parse( stream, SimpleResponse.class );
assertEquals( 18.24668429131D, response.getValue() );
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.io.InputStream;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

/**
* Created by ruhan on 12/19/17.
Expand All @@ -33,6 +34,7 @@ public class SubclassMapperTest
public void renderer() throws Exception
{
String result = new RWXMapper().render( getInstance() );
assertNotNull( result );
}

@Test
Expand Down Expand Up @@ -73,6 +75,4 @@ private GetBuildDescriptionResponse getInstance()
response.setValue( value );
return response;
}

}

22 changes: 10 additions & 12 deletions rwx/src/main/java/org/commonjava/rwx/api/RWXMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@

import org.commonjava.rwx.error.XmlRpcException;
import org.commonjava.rwx.error.XmlRpcFaultException;
import org.commonjava.rwx.core.Parser;
import org.commonjava.rwx.core.Registry;
import org.commonjava.rwx.core.Renderer;
import org.commonjava.rwx.core.XmlRpcParser;
import org.commonjava.rwx.model.Fault;
import org.commonjava.rwx.model.RpcObject;
Expand All @@ -37,9 +35,9 @@ public final class RWXMapper
/**
* Render an object to XML-RPC request or response string.
*
* @param obj
* @return
* @throws XmlRpcException
* @param obj the object to be rendered
* @return the XML string
* @throws XmlRpcException if the object cannot be rendered
*/
public String render( Object obj ) throws XmlRpcException
{
Expand All @@ -48,18 +46,18 @@ public String render( Object obj ) throws XmlRpcException
}

/**
* Parse a XML-RPC request or response stream (XML string) to an object.
* Parse ab XML-RPC request or response stream (XML string) to an object.
*
* @param stream
* @param type
* @param <T>
* @return
* @throws XmlRpcException
* @param stream the input stream consisting of XML-RPC request or response
* @param type the class of the object to be parsed
* @param <T> the type of the object to be parsed
* @return the object parsed from the XML-RPC stream
* @throws XmlRpcException if the stream cannot be parsed
*/
public <T> T parse( InputStream stream, Class<T> type ) throws XmlRpcException
{
final XmlRpcParser xmlRpcParser = new XmlRpcParser( stream );
RpcObject rpcObject = null;
RpcObject rpcObject;
try
{
rpcObject = xmlRpcParser.parse();
Expand Down
Loading