Skip to content
Open
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 @@ -27,6 +27,7 @@
import java.util.Map;

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

/**
Expand Down Expand Up @@ -191,4 +192,15 @@ private void assertMultiCallResponse( MultiCallResponse response )
assertEquals( 8829, data2_1Map.get( "id" ) );
}

@Test
public void parseMultiCallGetRPMResponseWithNilMembers() throws Exception
{
String source = getXMLString( "kojiMulticallGetRPMResponse" );
MultiCallResponse parsed =
new RWXMapper().parse( new ByteArrayInputStream( source.getBytes( StandardCharsets.UTF_8 ) ), MultiCallResponse.class );

List<MultiCallValueObj> valueObjs = parsed.getValueObjs();
assertEquals( 1, valueObjs.size() );
}

}
86 changes: 86 additions & 0 deletions rwx-test/src/test/resources/xml/kojiMulticallGetRPMResponse.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<?xml version='1.0'?>
<methodResponse>
<params>
<param>
<value><array><data>
<value><array><data>
<value><struct>
<member>
<name>arch</name>
<value><string>x86_64</string></value>
</member>
<member>
<name>build_id</name>
<value><nil/></value></member>
<member>
<name>buildroot_id</name>
<value><nil/></value></member>
<member>
<name>buildtime</name>
<value><int>1645136189</int></value>
</member>
<member>
<name>draft</name>
<value><nil/></value></member>
<member>
<name>epoch</name>
<value><nil/></value></member>
<member>
<name>external_repo_id</name>
<value><int>123</int></value>
</member>
<member>
<name>external_repo_name</name>
<value><string>rhel-8.10.0-z-build-repo</string></value>
</member>
<member>
<name>extra</name>
<value><nil/></value></member>
<member>
<name>id</name>
<value><int>12345678</int></value>
</member>
<member>
<name>metadata_only</name>
<value><boolean>0</boolean></value>
</member>
<member>
<name>name</name>
<value><string>cyrus-sasl-lib</string></value>
</member>
<member>
<name>payloadhash</name>
<value><string>93bf5b96d9dfd5201b016927d7a4b61c</string></value>
</member>
<member>
<name>release</name>
<value><string>6.el8_5</string></value>
</member>
<member>
<name>sha1header</name>
<value><string>598501096d3a56cb706f63cc921cc41258a267f4</string></value>
</member>
<member>
<name>sha256header</name>
<value><string>2a26ba019b2593773efb2f100c7c173fa906c61ba5031ced85f3f0aa39e7aa37</string></value>
</member>
<member>
<name>sha3_256header</name>
<value><nil/></value></member>
<member>
<name>sigmd5</name>
<value><string>93bf5b96d9dfd5201b016927d7a4b61c</string></value>
</member>
<member>
<name>size</name>
<value><nil/></value></member>
<member>
<name>version</name>
<value><string>2.1.27</string></value>
</member>
</struct></value>
</data></array></value>
</data></array></value>
</param>
</params>
</methodResponse>
25 changes: 23 additions & 2 deletions rwx/src/main/java/org/commonjava/rwx/vocab/ValueType.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,20 @@ public enum ValueType
@Override
public String toString( final Object value ) throws CoercionException
{
if ( value == null )
{
return null;
}
throw new CoercionException( "Cannot coerce STRUCT types." );
}

@Override
public Object fromString( final String value ) throws CoercionException
{
if ( value == null )
{
return null;
}
throw new CoercionException( "Cannot coerce STRUCT types." );
}
}, Map.class, XmlRpcConstants.STRUCT ),
Expand All @@ -54,12 +62,20 @@ public Object fromString( final String value ) throws CoercionException
@Override
public String toString( final Object value ) throws CoercionException
{
if ( value == null )
{
return null;
}
throw new CoercionException( "Cannot coerce ARRAY types." );
}

@Override
public Object fromString( final String value ) throws CoercionException
{
if ( value == null )
{
return null;
}
throw new CoercionException( "Cannot coerce ARRAY types." );
}
}, List.class, XmlRpcConstants.ARRAY ),
Expand All @@ -72,6 +88,11 @@ public Object fromString( final String value )
return Nil.NIL_VALUE;
}

@Override
public String toString( final Object value )
{
return null;
}
}, Nil.class, "nil" ),

INT( new ValueCoercion( "INT-to-String" )
Expand Down Expand Up @@ -108,12 +129,12 @@ public Object fromString( final String value ) throws CoercionException
}

/**
* If the value is of type Integer, convert it to Long
* If the value is of type Integer, convert it to Long, or null if nil.
*/
@Override
public Object upgradeCast( Object value )
{
if ( value instanceof Long )
if ( value == null || value instanceof Long )
{
return value;
}
Expand Down
54 changes: 54 additions & 0 deletions rwx/src/test/java/org/commonjava/rwx/vocab/ValueTypeNullTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Copyright © 2010 Red Hat, Inc. (http://github.com/Commonjava/commonjava)
*
* 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.commonjava.rwx.vocab;

import org.commonjava.rwx.error.CoercionException;
import org.commonjava.rwx.error.XmlRpcException;
import org.commonjava.rwx.util.ParseUtils;
import org.commonjava.rwx.util.RenderUtils;
import org.junit.Test;

import java.util.Collections;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;

public class ValueTypeNullTest
{
@Test
public void testNull() throws CoercionException, XmlRpcException
{
for ( final ValueType type : ValueType.values() )
{
if ( type == ValueType.NIL )
{
assertSame( Nil.NIL_VALUE, type.coercion().fromString( null ) );
}
else
{
assertNull( type.coercion().fromString( null ) );
}

assertNull( type.coercion().toString( null ) );
assertNull( type.coercion().upgradeCast( null ) );
}

assertNull( ParseUtils.upgradeCast( Long.class, null ) );
assertNull( ValueType.NIL.coercion().toString( Nil.NIL_VALUE ) );
assertEquals( RenderUtils.toXMLString( Collections.singletonList( null ) ), RenderUtils.toXMLString( Collections.singletonList( Nil.NIL_VALUE ) ) );
}
}
Loading