text
stringlengths 30
1.67M
|
---|
<s> package ch . ethz . inf . vs . californium . examples . ipso ; import ch . ethz . inf . vs . californium . coap . CodeRegistry ; import ch . ethz . inf . vs . californium . coap . GETRequest ; import ch . ethz . inf . vs . californium . coap . MediaTypeRegistry ; import ch . ethz . inf . vs . californium . endpoint . LocalResource ; public class DeviceSerial extends LocalResource { public DeviceSerial ( ) { super ( "<STR_LIT>" ) ; setTitle ( "<STR_LIT>" ) ; setResourceType ( "<STR_LIT>" ) ; setInterfaceDescription ( "<STR_LIT>" ) ; } @ Override public void performGET ( GETRequest request ) { request . respond ( CodeRegistry . RESP_CONTENT , "<STR_LIT>" , MediaTypeRegistry . TEXT_PLAIN ) ; } } </s> |
<s> package ch . ethz . inf . vs . californium . examples . ipso ; import ch . ethz . inf . vs . californium . coap . CodeRegistry ; import ch . ethz . inf . vs . californium . coap . GETRequest ; import ch . ethz . inf . vs . californium . coap . MediaTypeRegistry ; import ch . ethz . inf . vs . californium . endpoint . LocalResource ; public class DeviceModel extends LocalResource { public DeviceModel ( ) { super ( "<STR_LIT>" ) ; setTitle ( "<STR_LIT>" ) ; setResourceType ( "<STR_LIT>" ) ; setInterfaceDescription ( "<STR_LIT>" ) ; } @ Override public void performGET ( GETRequest request ) { request . respond ( CodeRegistry . RESP_CONTENT , "<STR_LIT>" , MediaTypeRegistry . TEXT_PLAIN ) ; } } </s> |
<s> package ch . ethz . inf . vs . californium . examples . ipso ; import ch . ethz . inf . vs . californium . coap . CodeRegistry ; import ch . ethz . inf . vs . californium . coap . GETRequest ; import ch . ethz . inf . vs . californium . coap . MediaTypeRegistry ; import ch . ethz . inf . vs . californium . coap . PUTRequest ; import ch . ethz . inf . vs . californium . endpoint . LocalResource ; public class DeviceName extends LocalResource { private String name = "<STR_LIT>" ; public DeviceName ( ) { super ( "<STR_LIT>" ) ; setTitle ( "<STR_LIT:Name>" ) ; setResourceType ( "<STR_LIT>" ) ; setInterfaceDescription ( "<STR_LIT>" ) ; } @ Override public void performGET ( GETRequest request ) { request . respond ( CodeRegistry . RESP_CONTENT , name , MediaTypeRegistry . TEXT_PLAIN ) ; } @ Override public void performPUT ( PUTRequest request ) { if ( request . getContentType ( ) != MediaTypeRegistry . TEXT_PLAIN ) { request . respond ( CodeRegistry . RESP_BAD_REQUEST , "<STR_LIT>" ) ; return ; } name = request . getPayloadString ( ) ; request . respond ( CodeRegistry . RESP_CHANGED ) ; } } </s> |
<s> package ch . ethz . inf . vs . californium . examples . ipso ; import java . util . Timer ; import java . util . TimerTask ; import ch . ethz . inf . vs . californium . coap . CodeRegistry ; import ch . ethz . inf . vs . californium . coap . GETRequest ; import ch . ethz . inf . vs . californium . coap . MediaTypeRegistry ; import ch . ethz . inf . vs . californium . endpoint . LocalResource ; public class PowerInstantaneous extends LocalResource { private double power = <NUM_LIT> ; public PowerInstantaneous ( ) { super ( "<STR_LIT>" ) ; setTitle ( "<STR_LIT>" ) ; setResourceType ( "<STR_LIT>" ) ; setInterfaceDescription ( "<STR_LIT>" ) ; isObservable ( true ) ; Timer timer = new Timer ( ) ; timer . schedule ( new TimeTask ( ) , <NUM_LIT:0> , <NUM_LIT:1000> ) ; } private class TimeTask extends TimerTask { @ Override public void run ( ) { if ( PowerRelay . getRelay ( ) ) { power = Math . round ( <NUM_LIT> * Math . random ( ) * ( PowerDimmer . getDimmer ( ) / <NUM_LIT> ) ) ; } else { if ( power == <NUM_LIT> ) { return ; } power = <NUM_LIT> ; } changed ( ) ; } } @ Override public void performGET ( GETRequest request ) { request . respond ( CodeRegistry . RESP_CONTENT , Double . toString ( power ) , MediaTypeRegistry . TEXT_PLAIN ) ; } } </s> |
<s> package ch . ethz . inf . vs . californium . examples . ipso ; import ch . ethz . inf . vs . californium . coap . CodeRegistry ; import ch . ethz . inf . vs . californium . coap . GETRequest ; import ch . ethz . inf . vs . californium . coap . MediaTypeRegistry ; import ch . ethz . inf . vs . californium . coap . PUTRequest ; import ch . ethz . inf . vs . californium . endpoint . LocalResource ; public class PowerRelay extends LocalResource { private static boolean on = true ; public static boolean getRelay ( ) { return on ; } public PowerRelay ( ) { super ( "<STR_LIT>" ) ; setTitle ( "<STR_LIT>" ) ; setResourceType ( "<STR_LIT>" ) ; setInterfaceDescription ( "<STR_LIT>" ) ; isObservable ( true ) ; } @ Override public void performGET ( GETRequest request ) { request . respond ( CodeRegistry . RESP_CONTENT , on ? "<STR_LIT:1>" : "<STR_LIT:0>" , MediaTypeRegistry . TEXT_PLAIN ) ; } @ Override public void performPUT ( PUTRequest request ) { if ( request . getContentType ( ) != MediaTypeRegistry . TEXT_PLAIN ) { request . respond ( CodeRegistry . RESP_BAD_REQUEST , "<STR_LIT>" ) ; return ; } String pl = request . getPayloadString ( ) ; if ( pl . equals ( "<STR_LIT:true>" ) || pl . equals ( "<STR_LIT:1>" ) ) { if ( on == true ) return ; on = true ; } else if ( pl . equals ( "<STR_LIT:false>" ) || pl . equals ( "<STR_LIT:0>" ) ) { if ( on == false ) return ; on = false ; } else { request . respond ( CodeRegistry . RESP_BAD_REQUEST , "<STR_LIT>" ) ; return ; } request . respond ( CodeRegistry . RESP_CHANGED ) ; changed ( ) ; } } </s> |
<s> package ch . ethz . inf . vs . californium . examples . ipso ; import java . util . Timer ; import java . util . TimerTask ; import ch . ethz . inf . vs . californium . coap . CodeRegistry ; import ch . ethz . inf . vs . californium . coap . GETRequest ; import ch . ethz . inf . vs . californium . coap . MediaTypeRegistry ; import ch . ethz . inf . vs . californium . endpoint . LocalResource ; public class PowerCumulative extends LocalResource { private double power = <NUM_LIT> ; public PowerCumulative ( ) { super ( "<STR_LIT>" ) ; setTitle ( "<STR_LIT>" ) ; setResourceType ( "<STR_LIT>" ) ; setInterfaceDescription ( "<STR_LIT>" ) ; isObservable ( true ) ; Timer timer = new Timer ( ) ; timer . schedule ( new TimeTask ( ) , <NUM_LIT:0> , <NUM_LIT:1000> ) ; } private class TimeTask extends TimerTask { @ Override public void run ( ) { if ( PowerRelay . getRelay ( ) ) { power += Math . round ( <NUM_LIT> * Math . random ( ) * ( PowerDimmer . getDimmer ( ) / <NUM_LIT> ) ) ; changed ( ) ; } } } @ Override public void performGET ( GETRequest request ) { request . respond ( CodeRegistry . RESP_CONTENT , Double . toString ( power ) , MediaTypeRegistry . TEXT_PLAIN ) ; } } </s> |
<s> package ch . ethz . inf . vs . californium . examples . ipso ; import java . util . Timer ; import java . util . TimerTask ; import ch . ethz . inf . vs . californium . coap . CodeRegistry ; import ch . ethz . inf . vs . californium . coap . GETRequest ; import ch . ethz . inf . vs . californium . coap . MediaTypeRegistry ; import ch . ethz . inf . vs . californium . endpoint . LocalResource ; public class DeviceBattery extends LocalResource { private double power = <NUM_LIT> ; public DeviceBattery ( ) { super ( "<STR_LIT>" ) ; setTitle ( "<STR_LIT>" ) ; setResourceType ( "<STR_LIT>" ) ; setInterfaceDescription ( "<STR_LIT>" ) ; isObservable ( true ) ; Timer timer = new Timer ( ) ; timer . schedule ( new TimeTask ( ) , <NUM_LIT:0> , <NUM_LIT:1000> ) ; } private class TimeTask extends TimerTask { @ Override public void run ( ) { power -= <NUM_LIT> * Math . random ( ) ; changed ( ) ; } } @ Override public void performGET ( GETRequest request ) { request . respond ( CodeRegistry . RESP_CONTENT , Double . toString ( Math . round ( power * <NUM_LIT> ) / <NUM_LIT> ) , MediaTypeRegistry . TEXT_PLAIN ) ; } } </s> |
<s> package ch . ethz . inf . vs . californium . examples . ipso ; import ch . ethz . inf . vs . californium . coap . CodeRegistry ; import ch . ethz . inf . vs . californium . coap . GETRequest ; import ch . ethz . inf . vs . californium . coap . MediaTypeRegistry ; import ch . ethz . inf . vs . californium . endpoint . LocalResource ; public class DeviceManufacturer extends LocalResource { public DeviceManufacturer ( ) { super ( "<STR_LIT>" ) ; setTitle ( "<STR_LIT>" ) ; setResourceType ( "<STR_LIT>" ) ; setInterfaceDescription ( "<STR_LIT>" ) ; } @ Override public void performGET ( GETRequest request ) { request . respond ( CodeRegistry . RESP_CONTENT , "<STR_LIT>" , MediaTypeRegistry . TEXT_PLAIN ) ; } } </s> |
<s> package ch . ethz . inf . vs . californium . examples ; import java . io . IOException ; import java . lang . reflect . Constructor ; import java . lang . reflect . InvocationTargetException ; import java . lang . reflect . Modifier ; import java . net . URI ; import java . net . URISyntaxException ; import java . util . ArrayList ; import java . util . Arrays ; import java . util . Collections ; import java . util . HashMap ; import java . util . List ; import java . util . Map ; import java . util . Timer ; import java . util . TimerTask ; import java . util . logging . Level ; import ch . ethz . inf . vs . californium . coap . * ; import ch . ethz . inf . vs . californium . endpoint . RemoteResource ; import ch . ethz . inf . vs . californium . endpoint . Resource ; import ch . ethz . inf . vs . californium . util . Log ; public class PlugtestClient { protected static final int PLUGTEST_BLOCK_SIZE = <NUM_LIT> ; private String serverURI = null ; private final Map < String , Class < ? > > testMap = new HashMap < String , Class < ? > > ( ) ; protected List < String > testsToRun = new ArrayList < String > ( ) ; protected List < String > summary = new ArrayList < String > ( ) ; public PlugtestClient ( String serverURI ) { if ( serverURI == null || serverURI . isEmpty ( ) ) { System . err . println ( "<STR_LIT>" ) ; throw new IllegalArgumentException ( "<STR_LIT>" ) ; } this . serverURI = serverURI ; for ( Class < ? > clientTest : this . getClass ( ) . getDeclaredClasses ( ) ) { if ( ! Modifier . isAbstract ( clientTest . getModifiers ( ) ) && ( clientTest . getSuperclass ( ) == TestClientAbstract . class ) ) { this . testMap . put ( clientTest . getSimpleName ( ) , clientTest ) ; } } } public void instantiateTests ( String ... testNames ) { testsToRun = Arrays . asList ( ( testNames == null || testNames . length == <NUM_LIT:0> ) ? this . testMap . keySet ( ) . toArray ( testNames ) : testNames ) ; Collections . sort ( testsToRun ) ; try { for ( String testString : testsToRun ) { Class < ? > testClass = this . testMap . get ( testString ) ; if ( testClass == null ) { System . err . println ( "<STR_LIT>" ) ; System . exit ( - <NUM_LIT:1> ) ; } Constructor < ? > [ ] constructors = testClass . getDeclaredConstructors ( ) ; if ( constructors . length == <NUM_LIT:0> ) { System . err . println ( "<STR_LIT>" ) ; System . exit ( - <NUM_LIT:1> ) ; } @ SuppressWarnings ( "<STR_LIT:unused>" ) TestClientAbstract testClient = ( TestClientAbstract ) constructors [ <NUM_LIT:0> ] . newInstance ( this , serverURI ) ; } waitForTests ( ) ; System . out . println ( "<STR_LIT>" ) ; for ( String result : summary ) { System . out . println ( result ) ; } } catch ( InstantiationException e ) { System . err . println ( "<STR_LIT>" ) ; e . printStackTrace ( ) ; } catch ( IllegalAccessException e ) { System . err . println ( "<STR_LIT>" ) ; e . printStackTrace ( ) ; } catch ( IllegalArgumentException e ) { System . err . println ( "<STR_LIT>" ) ; e . printStackTrace ( ) ; } catch ( SecurityException e ) { System . err . println ( "<STR_LIT>" ) ; e . printStackTrace ( ) ; } catch ( InvocationTargetException e ) { System . err . println ( "<STR_LIT>" ) ; e . printStackTrace ( ) ; } catch ( InterruptedException e ) { System . err . println ( "<STR_LIT>" ) ; e . printStackTrace ( ) ; } } public synchronized void waitForTests ( ) throws InterruptedException { while ( summary . size ( ) < testsToRun . size ( ) ) { wait ( ) ; } } public synchronized void tickOffTest ( ) { notify ( ) ; } public synchronized void addSummaryEntry ( String entry ) { summary . add ( entry ) ; } public static void main ( String [ ] args ) { if ( args . length == <NUM_LIT:0> || ! args [ <NUM_LIT:0> ] . startsWith ( "<STR_LIT>" ) ) { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; System . out . println ( ) ; System . out . println ( "<STR_LIT>" + PlugtestClient . class . getSimpleName ( ) + "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; System . out . println ( ) ; System . out . println ( "<STR_LIT>" ) ; System . out . print ( "<STR_LIT:U+0020>" ) ; for ( Class < ? > clientTest : PlugtestClient . class . getDeclaredClasses ( ) ) { if ( ! Modifier . isAbstract ( clientTest . getModifiers ( ) ) && ( clientTest . getSuperclass ( ) == TestClientAbstract . class ) ) { System . out . print ( "<STR_LIT:U+0020>" + clientTest . getSimpleName ( ) ) ; } } System . exit ( - <NUM_LIT:1> ) ; } Log . setLevel ( Level . WARNING ) ; Log . init ( ) ; Communicator . setupTransfer ( PLUGTEST_BLOCK_SIZE ) ; PlugtestClient clientFactory = new PlugtestClient ( args [ <NUM_LIT:0> ] ) ; clientFactory . instantiateTests ( Arrays . copyOfRange ( args , <NUM_LIT:1> , args . length ) ) ; } public abstract class TestClientAbstract { protected String testName = null ; protected boolean verbose = false ; protected boolean sync = true ; public TestClientAbstract ( String testName , boolean verbose , boolean synchronous ) { if ( testName == null || testName . isEmpty ( ) ) { throw new IllegalArgumentException ( "<STR_LIT>" ) ; } this . testName = testName ; this . verbose = verbose ; this . sync = synchronous ; } public TestClientAbstract ( String testName ) { this ( testName , false , true ) ; } protected synchronized void executeRequest ( Request request , String serverURI , String resourceUri ) { if ( serverURI == null || serverURI . isEmpty ( ) ) { System . err . println ( "<STR_LIT>" ) ; throw new IllegalArgumentException ( "<STR_LIT>" ) ; } if ( ! serverURI . endsWith ( "<STR_LIT:/>" ) && ! resourceUri . startsWith ( "<STR_LIT:/>" ) ) { resourceUri = "<STR_LIT:/>" + resourceUri ; } URI uri = null ; try { uri = new URI ( serverURI + resourceUri ) ; } catch ( URISyntaxException use ) { System . err . println ( "<STR_LIT>" + use . getMessage ( ) ) ; } request . setURI ( uri ) ; if ( request . requiresToken ( ) ) { request . setToken ( TokenManager . getInstance ( ) . acquireToken ( ) ) ; } request . registerResponseHandler ( new TestResponseHandler ( ) ) ; if ( sync ) { request . enableResponseQueue ( true ) ; } if ( verbose ) { System . out . println ( "<STR_LIT>" + this . testName + "<STR_LIT>" ) ; request . prettyPrint ( ) ; } try { request . execute ( ) ; if ( sync ) { request . receiveResponse ( ) ; } } catch ( IOException e ) { System . err . println ( "<STR_LIT>" + e . getMessage ( ) ) ; System . exit ( - <NUM_LIT:1> ) ; } catch ( InterruptedException e ) { System . err . println ( "<STR_LIT>" + e . getMessage ( ) ) ; System . exit ( - <NUM_LIT:1> ) ; } } protected class TestResponseHandler implements ResponseHandler { @ Override public void handleResponse ( Response response ) { System . out . println ( ) ; System . out . println ( "<STR_LIT>" + testName + "<STR_LIT>" ) ; if ( response != null ) { if ( verbose ) { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" + response . getRTT ( ) ) ; response . prettyPrint ( ) ; } System . out . println ( "<STR_LIT>" ) ; if ( checkResponse ( response . getRequest ( ) , response ) ) { System . out . println ( "<STR_LIT>" ) ; addSummaryEntry ( testName + "<STR_LIT>" ) ; } else { System . out . println ( "<STR_LIT>" ) ; addSummaryEntry ( testName + "<STR_LIT>" ) ; } tickOffTest ( ) ; } } } protected abstract boolean checkResponse ( Request request , Response response ) ; protected boolean checkInt ( int expected , int actual , String fieldName ) { boolean success = expected == actual ; if ( ! success ) { System . out . println ( "<STR_LIT>" + fieldName + "<STR_LIT::U+0020>" + expected + "<STR_LIT>" + actual ) ; } else { System . out . println ( "<STR_LIT>" + fieldName + String . format ( "<STR_LIT>" , actual ) ) ; } return success ; } protected boolean checkType ( Message . messageType expectedMessageType , Message . messageType actualMessageType ) { boolean success = expectedMessageType . equals ( actualMessageType ) ; if ( ! success ) { System . out . printf ( "<STR_LIT>" , expectedMessageType , actualMessageType ) ; } else { System . out . printf ( "<STR_LIT>" , actualMessageType . toString ( ) ) ; } return success ; } protected boolean hasContentType ( Response response ) { boolean success = response . hasOption ( OptionNumberRegistry . CONTENT_TYPE ) ; if ( ! success ) { System . out . println ( "<STR_LIT>" ) ; } else { System . out . printf ( "<STR_LIT>" , MediaTypeRegistry . toString ( response . getContentType ( ) ) ) ; } return success ; } protected boolean hasLocation ( Response response ) { boolean success = response . hasOption ( OptionNumberRegistry . LOCATION_PATH ) ; if ( ! success ) { System . out . println ( "<STR_LIT>" ) ; } else { System . out . printf ( "<STR_LIT>" , response . getLocationPath ( ) ) ; } return success ; } protected boolean hasObserve ( Response response , boolean invert ) { boolean success = response . hasOption ( OptionNumberRegistry . OBSERVE ) ; success ^= invert ; if ( ! success ) { System . out . println ( "<STR_LIT>" ) ; } else if ( ! invert ) { System . out . printf ( "<STR_LIT>" , response . getFirstOption ( OptionNumberRegistry . OBSERVE ) . getIntValue ( ) ) ; } else { System . out . println ( "<STR_LIT>" ) ; } return success ; } protected boolean hasObserve ( Response response ) { return hasObserve ( response , false ) ; } protected boolean checkOption ( Option expextedOption , Option actualOption ) { boolean success = actualOption != null && expextedOption . getOptionNumber ( ) == actualOption . getOptionNumber ( ) ; if ( ! success ) { System . out . printf ( "<STR_LIT>" , expextedOption . getOptionNumber ( ) ) ; } else { success &= expextedOption . toString ( ) . equals ( actualOption . toString ( ) ) ; if ( ! success ) { System . out . printf ( "<STR_LIT>" , expextedOption . toString ( ) , actualOption . toString ( ) ) ; } else { System . out . printf ( "<STR_LIT>" , actualOption . toString ( ) ) ; } } return success ; } protected boolean checkToken ( Option expextedOption , Option actualOption ) { boolean success = true ; if ( expextedOption . equals ( new Option ( TokenManager . emptyToken , OptionNumberRegistry . TOKEN ) ) ) { success = actualOption == null ; if ( ! success ) { System . out . printf ( "<STR_LIT>" , actualOption ) ; } else { System . out . println ( "<STR_LIT>" ) ; } return success ; } else { success = actualOption . getRawValue ( ) . length <= <NUM_LIT:8> ; success &= actualOption . getRawValue ( ) . length >= <NUM_LIT:1> ; if ( ! success ) { System . out . printf ( "<STR_LIT>" , expextedOption , actualOption ) ; return success ; } success &= expextedOption . toString ( ) . equals ( actualOption . toString ( ) ) ; if ( ! success ) { System . out . printf ( "<STR_LIT>" , expextedOption , actualOption ) ; } else { System . out . printf ( "<STR_LIT>" , actualOption ) ; } return success ; } } protected boolean checkDiscovery ( String expextedAttribute , String actualDiscovery ) { Resource res = RemoteResource . newRoot ( actualDiscovery ) ; List < Option > query = new ArrayList < Option > ( ) ; query . add ( new Option ( expextedAttribute , OptionNumberRegistry . URI_QUERY ) ) ; boolean success = true ; for ( Resource sub : res . getSubResources ( ) ) { success &= LinkFormat . matches ( sub , query ) ; if ( ! success ) { System . out . printf ( "<STR_LIT>" , expextedAttribute , LinkFormat . serialize ( sub , null , false ) ) ; } } if ( success ) { System . out . println ( "<STR_LIT>" ) ; } return success ; } } public class CC01 extends TestClientAbstract { public static final String RESOURCE_URI = "<STR_LIT>" ; public static final int EXPECTED_RESPONSE_CODE = <NUM_LIT> ; public CC01 ( String serverURI ) { super ( CC01 . class . getSimpleName ( ) ) ; Request request = new GETRequest ( ) ; executeRequest ( request , serverURI , RESOURCE_URI ) ; } protected boolean checkResponse ( Request request , Response response ) { boolean success = true ; success &= checkType ( Message . messageType . ACK , response . getType ( ) ) ; success &= checkInt ( EXPECTED_RESPONSE_CODE , response . getCode ( ) , "<STR_LIT:code>" ) ; success &= checkInt ( request . getMID ( ) , response . getMID ( ) , "<STR_LIT>" ) ; success &= hasContentType ( response ) ; return success ; } } public class CC02 extends TestClientAbstract { public static final String RESOURCE_URI = "<STR_LIT>" ; public static final int EXPECTED_RESPONSE_CODE = <NUM_LIT> ; public CC02 ( String serverURI ) { super ( CC02 . class . getSimpleName ( ) ) ; Request request = new POSTRequest ( ) ; request . setPayload ( "<STR_LIT>" , MediaTypeRegistry . TEXT_PLAIN ) ; executeRequest ( request , serverURI , RESOURCE_URI ) ; } protected boolean checkResponse ( Request request , Response response ) { boolean success = true ; success &= checkType ( Message . messageType . ACK , response . getType ( ) ) ; success &= checkInt ( EXPECTED_RESPONSE_CODE , response . getCode ( ) , "<STR_LIT:code>" ) ; success &= checkInt ( request . getMID ( ) , response . getMID ( ) , "<STR_LIT>" ) ; return success ; } } public class CC03 extends TestClientAbstract { public static final String RESOURCE_URI = "<STR_LIT>" ; public static final int EXPECTED_RESPONSE_CODE = <NUM_LIT> ; public CC03 ( String serverURI ) { super ( CC03 . class . getSimpleName ( ) ) ; Request request = new PUTRequest ( ) ; request . setPayload ( "<STR_LIT>" , MediaTypeRegistry . TEXT_PLAIN ) ; executeRequest ( request , serverURI , RESOURCE_URI ) ; } protected boolean checkResponse ( Request request , Response response ) { boolean success = true ; success &= checkType ( Message . messageType . ACK , response . getType ( ) ) ; success &= checkInt ( EXPECTED_RESPONSE_CODE , response . getCode ( ) , "<STR_LIT:code>" ) ; success &= checkInt ( request . getMID ( ) , response . getMID ( ) , "<STR_LIT>" ) ; return success ; } } public class CC04 extends TestClientAbstract { public static final String RESOURCE_URI = "<STR_LIT>" ; public static final int EXPECTED_RESPONSE_CODE = <NUM_LIT> ; public CC04 ( String serverURI ) { super ( CC04 . class . getSimpleName ( ) ) ; Request request = new DELETERequest ( ) ; executeRequest ( request , serverURI , RESOURCE_URI ) ; } protected boolean checkResponse ( Request request , Response response ) { boolean success = true ; success &= checkType ( Message . messageType . ACK , response . getType ( ) ) ; success &= checkInt ( EXPECTED_RESPONSE_CODE , response . getCode ( ) , "<STR_LIT:code>" ) ; success &= checkInt ( request . getMID ( ) , response . getMID ( ) , "<STR_LIT>" ) ; return success ; } } public class CC05 extends TestClientAbstract { public static final String RESOURCE_URI = "<STR_LIT>" ; public static final int EXPECTED_RESPONSE_CODE = <NUM_LIT> ; public CC05 ( String serverURI ) { super ( CC05 . class . getSimpleName ( ) ) ; Request request = new Request ( CodeRegistry . METHOD_GET , false ) ; executeRequest ( request , serverURI , RESOURCE_URI ) ; } protected boolean checkResponse ( Request request , Response response ) { boolean success = true ; success &= checkType ( Message . messageType . NON , response . getType ( ) ) ; success &= checkInt ( EXPECTED_RESPONSE_CODE , response . getCode ( ) , "<STR_LIT:code>" ) ; success &= hasContentType ( response ) ; return success ; } } public class CC06 extends TestClientAbstract { public static final String RESOURCE_URI = "<STR_LIT>" ; public static final int EXPECTED_RESPONSE_CODE = <NUM_LIT> ; public CC06 ( String serverURI ) { super ( CC06 . class . getSimpleName ( ) ) ; Request request = new Request ( CodeRegistry . METHOD_POST , false ) ; request . setPayload ( "<STR_LIT>" , MediaTypeRegistry . TEXT_PLAIN ) ; executeRequest ( request , serverURI , RESOURCE_URI ) ; } protected boolean checkResponse ( Request request , Response response ) { boolean success = true ; success &= checkType ( Message . messageType . NON , response . getType ( ) ) ; success &= checkInt ( EXPECTED_RESPONSE_CODE , response . getCode ( ) , "<STR_LIT:code>" ) ; return success ; } } public class CC07 extends TestClientAbstract { public static final String RESOURCE_URI = "<STR_LIT>" ; public static final int EXPECTED_RESPONSE_CODE = <NUM_LIT> ; public CC07 ( String serverURI ) { super ( CC07 . class . getSimpleName ( ) ) ; Request request = new Request ( CodeRegistry . METHOD_PUT , false ) ; request . setPayload ( "<STR_LIT>" , MediaTypeRegistry . TEXT_PLAIN ) ; executeRequest ( request , serverURI , RESOURCE_URI ) ; } protected boolean checkResponse ( Request request , Response response ) { boolean success = true ; success &= checkType ( Message . messageType . NON , response . getType ( ) ) ; success &= checkInt ( EXPECTED_RESPONSE_CODE , response . getCode ( ) , "<STR_LIT:code>" ) ; return success ; } } public class CC08 extends TestClientAbstract { public static final String RESOURCE_URI = "<STR_LIT>" ; public static final int EXPECTED_RESPONSE_CODE = <NUM_LIT> ; public CC08 ( String serverURI ) { super ( CC08 . class . getSimpleName ( ) ) ; Request request = new Request ( CodeRegistry . METHOD_DELETE , false ) ; executeRequest ( request , serverURI , RESOURCE_URI ) ; } protected boolean checkResponse ( Request request , Response response ) { boolean success = true ; success &= checkType ( Message . messageType . NON , response . getType ( ) ) ; success &= checkInt ( EXPECTED_RESPONSE_CODE , response . getCode ( ) , "<STR_LIT:code>" ) ; return success ; } } public class CC09 extends TestClientAbstract { public static final String RESOURCE_URI = "<STR_LIT>" ; public static final int EXPECTED_RESPONSE_CODE = <NUM_LIT> ; public CC09 ( String serverURI ) { super ( CC09 . class . getSimpleName ( ) ) ; Request request = new Request ( CodeRegistry . METHOD_GET , true ) ; executeRequest ( request , serverURI , RESOURCE_URI ) ; } protected boolean checkResponse ( Request request , Response response ) { boolean success = true ; success &= checkType ( Message . messageType . CON , response . getType ( ) ) ; success &= checkInt ( EXPECTED_RESPONSE_CODE , response . getCode ( ) , "<STR_LIT:code>" ) ; success &= hasContentType ( response ) ; return success ; } } public class CC10 extends TestClientAbstract { public static final String RESOURCE_URI = "<STR_LIT>" ; public static final int EXPECTED_RESPONSE_CODE = <NUM_LIT> ; public CC10 ( String serverURI ) { super ( CC10 . class . getSimpleName ( ) ) ; Request request = new Request ( CodeRegistry . METHOD_GET , true ) ; request . setToken ( TokenManager . getInstance ( ) . acquireToken ( false ) ) ; executeRequest ( request , serverURI , RESOURCE_URI ) ; } protected boolean checkResponse ( Request request , Response response ) { boolean success = true ; success &= checkType ( Message . messageType . ACK , response . getType ( ) ) ; success &= checkInt ( EXPECTED_RESPONSE_CODE , response . getCode ( ) , "<STR_LIT:code>" ) ; success &= checkToken ( request . getFirstOption ( OptionNumberRegistry . TOKEN ) , response . getFirstOption ( OptionNumberRegistry . TOKEN ) ) ; success &= hasContentType ( response ) ; return success ; } } public class CC11 extends TestClientAbstract { public static final String RESOURCE_URI = "<STR_LIT>" ; public static final int EXPECTED_RESPONSE_CODE = <NUM_LIT> ; public CC11 ( String serverURI ) { super ( CC11 . class . getSimpleName ( ) ) ; Request request = new Request ( CodeRegistry . METHOD_GET , true ) ; request . setToken ( TokenManager . getInstance ( ) . acquireToken ( true ) ) ; executeRequest ( request , serverURI , RESOURCE_URI ) ; } protected boolean checkResponse ( Request request , Response response ) { boolean success = true ; success &= checkType ( Message . messageType . ACK , response . getType ( ) ) ; success &= checkInt ( EXPECTED_RESPONSE_CODE , response . getCode ( ) , "<STR_LIT:code>" ) ; success &= checkToken ( new Option ( TokenManager . emptyToken , OptionNumberRegistry . TOKEN ) , response . getFirstOption ( OptionNumberRegistry . TOKEN ) ) ; success &= hasContentType ( response ) ; return success ; } } public class CC12 extends TestClientAbstract { public static final String RESOURCE_URI = "<STR_LIT>" ; public static final int EXPECTED_RESPONSE_CODE = <NUM_LIT> ; public CC12 ( String serverURI ) { super ( CC12 . class . getSimpleName ( ) ) ; Request request = new Request ( CodeRegistry . METHOD_GET , true ) ; executeRequest ( request , serverURI , RESOURCE_URI ) ; } protected boolean checkResponse ( Request request , Response response ) { boolean success = true ; success &= checkType ( Message . messageType . ACK , response . getType ( ) ) ; success &= checkInt ( EXPECTED_RESPONSE_CODE , response . getCode ( ) , "<STR_LIT:code>" ) ; success &= hasContentType ( response ) ; return success ; } } public class CC13 extends TestClientAbstract { public static final String RESOURCE_URI = "<STR_LIT>" ; public static final int EXPECTED_RESPONSE_CODE = <NUM_LIT> ; public CC13 ( String serverURI ) { super ( CC13 . class . getSimpleName ( ) ) ; Request request = new Request ( CodeRegistry . METHOD_GET , true ) ; request . setOption ( new Option ( "<STR_LIT>" , OptionNumberRegistry . URI_QUERY ) ) ; request . addOption ( new Option ( "<STR_LIT>" , OptionNumberRegistry . URI_QUERY ) ) ; request . addOption ( new Option ( "<STR_LIT>" , OptionNumberRegistry . URI_QUERY ) ) ; executeRequest ( request , serverURI , RESOURCE_URI ) ; } protected boolean checkResponse ( Request request , Response response ) { boolean success = true ; success &= checkType ( Message . messageType . ACK , response . getType ( ) ) || checkType ( Message . messageType . CON , response . getType ( ) ) ; success &= checkInt ( EXPECTED_RESPONSE_CODE , response . getCode ( ) , "<STR_LIT:code>" ) ; success &= hasContentType ( response ) ; return success ; } } public class CC16 extends TestClientAbstract { public static final String RESOURCE_URI = "<STR_LIT>" ; public static final int EXPECTED_RESPONSE_CODE = <NUM_LIT> ; public CC16 ( String serverURI ) { super ( CC16 . class . getSimpleName ( ) ) ; Request request = new Request ( CodeRegistry . METHOD_GET , false ) ; executeRequest ( request , serverURI , RESOURCE_URI ) ; } protected boolean checkResponse ( Request request , Response response ) { boolean success = true ; success &= checkType ( Message . messageType . NON , response . getType ( ) ) ; success &= checkInt ( EXPECTED_RESPONSE_CODE , response . getCode ( ) , "<STR_LIT:code>" ) ; success &= hasContentType ( response ) ; return success ; } } public class CL01 extends TestClientAbstract { public static final String RESOURCE_URI = "<STR_LIT>" ; public static final int EXPECTED_RESPONSE_CODE = <NUM_LIT> ; public CL01 ( String serverURI ) { super ( CL01 . class . getSimpleName ( ) ) ; Request request = new Request ( CodeRegistry . METHOD_GET , true ) ; executeRequest ( request , serverURI , RESOURCE_URI ) ; } protected boolean checkResponse ( Request request , Response response ) { boolean success = true ; success &= checkType ( Message . messageType . ACK , response . getType ( ) ) ; success &= checkInt ( EXPECTED_RESPONSE_CODE , response . getCode ( ) , "<STR_LIT:code>" ) ; success &= checkOption ( new Option ( MediaTypeRegistry . APPLICATION_LINK_FORMAT , OptionNumberRegistry . CONTENT_TYPE ) , response . getFirstOption ( OptionNumberRegistry . CONTENT_TYPE ) ) ; return success ; } } public class CL02 extends TestClientAbstract { public static final String RESOURCE_URI = "<STR_LIT>" ; public static final int EXPECTED_RESPONSE_CODE = <NUM_LIT> ; public static final String EXPECTED_RT = "<STR_LIT>" ; public CL02 ( String serverURI ) { super ( CL02 . class . getSimpleName ( ) ) ; Request request = new Request ( CodeRegistry . METHOD_GET , true ) ; request . setOption ( new Option ( EXPECTED_RT , OptionNumberRegistry . URI_QUERY ) ) ; executeRequest ( request , serverURI , RESOURCE_URI ) ; } protected boolean checkResponse ( Request request , Response response ) { boolean success = true ; success &= checkType ( Message . messageType . ACK , response . getType ( ) ) ; success &= checkInt ( EXPECTED_RESPONSE_CODE , response . getCode ( ) , "<STR_LIT:code>" ) ; success &= checkOption ( new Option ( MediaTypeRegistry . APPLICATION_LINK_FORMAT , OptionNumberRegistry . CONTENT_TYPE ) , response . getFirstOption ( OptionNumberRegistry . CONTENT_TYPE ) ) ; success &= checkDiscovery ( EXPECTED_RT , response . getPayloadString ( ) ) ; return success ; } } public class CB01 extends TestClientAbstract { public static final String RESOURCE_URI = "<STR_LIT>" ; public static final int EXPECTED_RESPONSE_CODE = <NUM_LIT> ; public CB01 ( String serverURI ) { super ( CB01 . class . getSimpleName ( ) ) ; Request request = new Request ( CodeRegistry . METHOD_GET , true ) ; request . setOption ( new BlockOption ( OptionNumberRegistry . BLOCK2 , <NUM_LIT:0> , BlockOption . encodeSZX ( PLUGTEST_BLOCK_SIZE ) , false ) ) ; executeRequest ( request , serverURI , RESOURCE_URI ) ; } protected boolean checkResponse ( Request request , Response response ) { boolean success = response . hasOption ( OptionNumberRegistry . BLOCK2 ) ; if ( ! success ) { System . out . println ( "<STR_LIT>" ) ; } else { int maxNUM = ( ( BlockOption ) response . getFirstOption ( OptionNumberRegistry . BLOCK2 ) ) . getNUM ( ) ; success &= checkType ( Message . messageType . ACK , response . getType ( ) ) ; success &= checkInt ( EXPECTED_RESPONSE_CODE , response . getCode ( ) , "<STR_LIT:code>" ) ; success &= checkOption ( new BlockOption ( OptionNumberRegistry . BLOCK2 , maxNUM , BlockOption . encodeSZX ( PLUGTEST_BLOCK_SIZE ) , false ) , response . getFirstOption ( OptionNumberRegistry . BLOCK2 ) ) ; success &= hasContentType ( response ) ; } return success ; } } public class CB02 extends TestClientAbstract { public static final String RESOURCE_URI = "<STR_LIT>" ; public static final int EXPECTED_RESPONSE_CODE = <NUM_LIT> ; public CB02 ( String serverURI ) { super ( CB02 . class . getSimpleName ( ) ) ; Request request = new Request ( CodeRegistry . METHOD_GET , true ) ; executeRequest ( request , serverURI , RESOURCE_URI ) ; } protected boolean checkResponse ( Request request , Response response ) { boolean success = response . hasOption ( OptionNumberRegistry . BLOCK2 ) ; if ( ! success ) { System . out . println ( "<STR_LIT>" ) ; } else { int maxNUM = ( ( BlockOption ) response . getFirstOption ( OptionNumberRegistry . BLOCK2 ) ) . getNUM ( ) ; success &= checkType ( Message . messageType . ACK , response . getType ( ) ) ; success &= checkInt ( EXPECTED_RESPONSE_CODE , response . getCode ( ) , "<STR_LIT:code>" ) ; success &= checkOption ( new BlockOption ( OptionNumberRegistry . BLOCK2 , maxNUM , BlockOption . encodeSZX ( PLUGTEST_BLOCK_SIZE ) , false ) , response . getFirstOption ( OptionNumberRegistry . BLOCK2 ) ) ; success &= hasContentType ( response ) ; } return success ; } } public class CB03 extends TestClientAbstract { public static final String RESOURCE_URI = "<STR_LIT>" ; public static final int EXPECTED_RESPONSE_CODE = <NUM_LIT> ; public CB03 ( String serverURI ) { super ( CB03 . class . getSimpleName ( ) ) ; Request request = new Request ( CodeRegistry . METHOD_PUT , true ) ; StringBuilder builder = new StringBuilder ( ) ; for ( int i = <NUM_LIT:0> ; i < <NUM_LIT:20> ; ++ i ) { for ( int j = <NUM_LIT:0> ; j < <NUM_LIT> ; ++ j ) { builder . append ( Integer . toString ( i % <NUM_LIT:10> ) ) ; } builder . append ( '<STR_LIT:\n>' ) ; } request . setPayload ( builder . toString ( ) , MediaTypeRegistry . TEXT_PLAIN ) ; executeRequest ( request , serverURI , RESOURCE_URI ) ; } protected boolean checkResponse ( Request request , Response response ) { boolean success = response . hasOption ( OptionNumberRegistry . BLOCK1 ) ; if ( ! success ) { System . out . println ( "<STR_LIT>" ) ; } else { int maxNUM = ( ( BlockOption ) response . getFirstOption ( OptionNumberRegistry . BLOCK1 ) ) . getNUM ( ) ; success &= checkType ( Message . messageType . ACK , response . getType ( ) ) ; success &= checkInt ( EXPECTED_RESPONSE_CODE , response . getCode ( ) , "<STR_LIT:code>" ) ; success &= checkOption ( new BlockOption ( OptionNumberRegistry . BLOCK1 , maxNUM , BlockOption . encodeSZX ( PLUGTEST_BLOCK_SIZE ) , false ) , response . getFirstOption ( OptionNumberRegistry . BLOCK1 ) ) ; } return success ; } } public class CB04 extends TestClientAbstract { public static final String RESOURCE_URI = "<STR_LIT>" ; public static final int EXPECTED_RESPONSE_CODE = <NUM_LIT> ; public CB04 ( String serverURI ) { super ( CB04 . class . getSimpleName ( ) ) ; Request request = new Request ( CodeRegistry . METHOD_POST , true ) ; StringBuilder builder = new StringBuilder ( ) ; for ( int i = <NUM_LIT:0> ; i < <NUM_LIT:20> ; ++ i ) { for ( int j = <NUM_LIT:0> ; j < <NUM_LIT> ; ++ j ) { builder . append ( Integer . toString ( i % <NUM_LIT:10> ) ) ; } builder . append ( '<STR_LIT:\n>' ) ; } request . setPayload ( builder . toString ( ) , MediaTypeRegistry . TEXT_PLAIN ) ; executeRequest ( request , serverURI , RESOURCE_URI ) ; } protected boolean checkResponse ( Request request , Response response ) { boolean success = response . hasOption ( OptionNumberRegistry . BLOCK1 ) ; if ( ! success ) { System . out . println ( "<STR_LIT>" ) ; } else { int maxNUM = ( ( BlockOption ) response . getFirstOption ( OptionNumberRegistry . BLOCK1 ) ) . getNUM ( ) ; success &= checkType ( Message . messageType . ACK , response . getType ( ) ) ; success &= checkInt ( EXPECTED_RESPONSE_CODE , response . getCode ( ) , "<STR_LIT:code>" ) ; success &= checkOption ( new BlockOption ( OptionNumberRegistry . BLOCK1 , maxNUM , BlockOption . encodeSZX ( PLUGTEST_BLOCK_SIZE ) , false ) , response . getFirstOption ( OptionNumberRegistry . BLOCK1 ) ) ; success &= hasLocation ( response ) ; } return success ; } } public class CO01_02 extends TestClientAbstract { public static final String RESOURCE_URI = "<STR_LIT>" ; public static final int EXPECTED_RESPONSE_CODE = <NUM_LIT> ; public CO01_02 ( String serverURI ) { super ( CO01_02 . class . getSimpleName ( ) ) ; Request request = new Request ( CodeRegistry . METHOD_GET , true ) ; request . setOption ( new Option ( <NUM_LIT:0> , OptionNumberRegistry . OBSERVE ) ) ; executeRequest ( request , serverURI , RESOURCE_URI ) ; } protected boolean checkResponse ( Request request , Response response ) { boolean success = true ; success &= checkInt ( EXPECTED_RESPONSE_CODE , response . getCode ( ) , "<STR_LIT:code>" ) ; success &= hasObserve ( response ) ; success &= hasContentType ( response ) ; return success ; } @ Override protected synchronized void executeRequest ( Request request , String serverURI , String resourceUri ) { if ( serverURI == null || serverURI . isEmpty ( ) ) { throw new IllegalArgumentException ( "<STR_LIT>" ) ; } if ( ! serverURI . endsWith ( "<STR_LIT:/>" ) && ! resourceUri . startsWith ( "<STR_LIT:/>" ) ) { resourceUri = "<STR_LIT:/>" + resourceUri ; } URI uri = null ; try { uri = new URI ( serverURI + resourceUri ) ; } catch ( URISyntaxException use ) { throw new IllegalArgumentException ( "<STR_LIT>" + use . getMessage ( ) ) ; } request . setURI ( uri ) ; if ( request . requiresToken ( ) ) { request . setToken ( TokenManager . getInstance ( ) . acquireToken ( ) ) ; } request . enableResponseQueue ( true ) ; int observeLoop = <NUM_LIT:5> ; if ( verbose ) { System . out . println ( "<STR_LIT>" + this . testName + "<STR_LIT>" ) ; request . prettyPrint ( ) ; } try { Response response = null ; boolean success = true ; request . execute ( ) ; System . out . println ( ) ; System . out . println ( "<STR_LIT>" + testName + "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; for ( int l = <NUM_LIT:0> ; l < observeLoop ; ++ l ) { response = request . receiveResponse ( ) ; if ( response != null ) { if ( verbose ) { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" + response . getRTT ( ) ) ; response . prettyPrint ( ) ; } success &= checkResponse ( response . getRequest ( ) , response ) ; if ( ! hasObserve ( response ) ) { break ; } } } request . removeOptions ( OptionNumberRegistry . OBSERVE ) ; request . setMID ( - <NUM_LIT:1> ) ; request . execute ( ) ; response = request . receiveResponse ( ) ; success &= hasObserve ( response , true ) ; if ( success ) { System . out . println ( "<STR_LIT>" ) ; addSummaryEntry ( testName + "<STR_LIT>" ) ; } else { System . out . println ( "<STR_LIT>" ) ; addSummaryEntry ( testName + "<STR_LIT>" ) ; } tickOffTest ( ) ; } catch ( IOException e ) { System . err . println ( "<STR_LIT>" + e . getMessage ( ) ) ; System . exit ( - <NUM_LIT:1> ) ; } catch ( InterruptedException e ) { System . err . println ( "<STR_LIT>" + e . getMessage ( ) ) ; System . exit ( - <NUM_LIT:1> ) ; } } } public class CO03_05 extends TestClientAbstract { public static final String RESOURCE_URI = "<STR_LIT>" ; public static final int EXPECTED_RESPONSE_CODE = <NUM_LIT> ; private Timer timer = new Timer ( true ) ; private class MaxAgeTask extends TimerTask { private Request request ; public MaxAgeTask ( Request request ) { this . request = request ; } @ Override public void run ( ) { this . request . handleTimeout ( ) ; } } public CO03_05 ( String serverURI ) { super ( CO03_05 . class . getSimpleName ( ) ) ; Request request = new Request ( CodeRegistry . METHOD_GET , true ) ; request . setOption ( new Option ( <NUM_LIT:0> , OptionNumberRegistry . OBSERVE ) ) ; executeRequest ( request , serverURI , RESOURCE_URI ) ; } protected boolean checkResponse ( Request request , Response response ) { boolean success = true ; success &= checkInt ( EXPECTED_RESPONSE_CODE , response . getCode ( ) , "<STR_LIT:code>" ) ; success &= hasObserve ( response ) ; success &= hasContentType ( response ) ; return success ; } @ Override protected synchronized void executeRequest ( Request request , String serverURI , String resourceUri ) { if ( serverURI == null || serverURI . isEmpty ( ) ) { throw new IllegalArgumentException ( "<STR_LIT>" ) ; } if ( ! serverURI . endsWith ( "<STR_LIT:/>" ) && ! resourceUri . startsWith ( "<STR_LIT:/>" ) ) { resourceUri = "<STR_LIT:/>" + resourceUri ; } URI uri = null ; try { uri = new URI ( serverURI + resourceUri ) ; } catch ( URISyntaxException use ) { throw new IllegalArgumentException ( "<STR_LIT>" + use . getMessage ( ) ) ; } request . setURI ( uri ) ; if ( request . requiresToken ( ) ) { request . setToken ( TokenManager . getInstance ( ) . acquireToken ( ) ) ; } if ( sync ) { request . enableResponseQueue ( true ) ; } int observeLoop = <NUM_LIT:5> ; if ( verbose ) { System . out . println ( "<STR_LIT>" + this . testName + "<STR_LIT>" ) ; request . prettyPrint ( ) ; } try { Response response = null ; boolean success = true ; boolean timedOut = false ; MaxAgeTask timeout = null ; request . execute ( ) ; System . out . println ( ) ; System . out . println ( "<STR_LIT>" + testName + "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; for ( int l = <NUM_LIT:0> ; l < observeLoop ; ++ l ) { response = request . receiveResponse ( ) ; if ( response != null ) { if ( l >= <NUM_LIT:2> && ! timedOut ) { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" ) ; } if ( timeout != null ) { timeout . cancel ( ) ; timer . purge ( ) ; } long time = response . getMaxAge ( ) * <NUM_LIT:1000> ; timeout = new MaxAgeTask ( request ) ; timer . schedule ( timeout , time + <NUM_LIT:1000> ) ; if ( verbose ) { System . out . println ( "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" + response . getRTT ( ) ) ; response . prettyPrint ( ) ; } success &= checkResponse ( response . getRequest ( ) , response ) ; if ( ! hasObserve ( response ) ) { break ; } } else { timedOut = true ; System . out . println ( "<STR_LIT>" ) ; request . setMID ( - <NUM_LIT:1> ) ; request . execute ( ) ; ++ observeLoop ; } } response . reject ( ) ; success &= timedOut ; if ( success ) { System . out . println ( "<STR_LIT>" ) ; addSummaryEntry ( testName + "<STR_LIT>" ) ; } else { System . out . println ( "<STR_LIT>" ) ; addSummaryEntry ( testName + "<STR_LIT>" ) ; } tickOffTest ( ) ; } catch ( IOException e ) { System . err . println ( "<STR_LIT>" + e . getMessage ( ) ) ; System . exit ( - <NUM_LIT:1> ) ; } catch ( InterruptedException e ) { System . err . println ( "<STR_LIT>" + e . getMessage ( ) ) ; System . exit ( - <NUM_LIT:1> ) ; } } } public class CO04 extends TestClientAbstract { public static final String RESOURCE_URI = "<STR_LIT>" ; public static final int EXPECTED_RESPONSE_CODE = <NUM_LIT> ; public CO04 ( String serverURI ) { super ( CO04 . class . getSimpleName ( ) ) ; Request request = new Request ( CodeRegistry . METHOD_GET , true ) ; request . setOption ( new Option ( <NUM_LIT:0> , OptionNumberRegistry . OBSERVE ) ) ; executeRequest ( request , serverURI , RESOURCE_URI ) ; } protected boolean checkResponse ( Request request , Response response ) { boolean success = true ; success &= checkInt ( EXPECTED_RESPONSE_CODE , response . getCode ( ) , "<STR_LIT:code>" ) ; success &= hasObserve ( response ) ; success &= hasContentType ( response ) ; return success ; } } } </s> |
<s> package org . fluentd . logger . util ; import java . io . IOException ; import java . net . ServerSocket ; import java . net . Socket ; import java . util . HashMap ; import java . util . concurrent . atomic . AtomicBoolean ; import org . fluentd . logger . sender . Event ; import org . msgpack . MessagePack ; import org . msgpack . packer . Packer ; import org . msgpack . template . Templates ; import org . msgpack . type . Value ; import org . msgpack . unpacker . Unpacker ; public class MockFluentd extends Thread { public static interface MockProcess { public void process ( MessagePack msgpack , Socket socket ) throws IOException ; } public static class MockEventTemplate extends Event . EventTemplate { public static MockEventTemplate INSTANCE = new MockEventTemplate ( ) ; public void write ( Packer pk , Event v , boolean required ) throws IOException { throw new UnsupportedOperationException ( "<STR_LIT>" ) ; } public Event read ( Unpacker u , Event to , boolean required ) throws IOException { if ( ! required && u . trySkipNil ( ) ) { return null ; } to = new Event ( ) ; u . readArrayBegin ( ) ; { to . tag = Templates . TString . read ( u , null , required ) ; to . timestamp = Templates . TLong . read ( u , null , required ) ; int size = u . readMapBegin ( ) ; to . data = new HashMap < String , Object > ( size ) ; { for ( int i = <NUM_LIT:0> ; i < size ; i ++ ) { String key = ( String ) toObject ( u , u . readValue ( ) ) ; Object value = toObject ( u , u . readValue ( ) ) ; to . data . put ( key , value ) ; } } u . readMapEnd ( ) ; } u . readArrayEnd ( ) ; return to ; } private static Object toObject ( Unpacker u , Value v ) { if ( v . isNilValue ( ) ) { v . asNilValue ( ) ; return null ; } else if ( v . isRawValue ( ) ) { return v . asRawValue ( ) . getString ( ) ; } else if ( v . isBooleanValue ( ) ) { return v . asBooleanValue ( ) . getBoolean ( ) ; } else if ( v . isFloatValue ( ) ) { return v . asFloatValue ( ) . getDouble ( ) ; } else if ( v . isIntegerValue ( ) ) { return v . asIntegerValue ( ) . getLong ( ) ; } else if ( v . isMapValue ( ) ) { throw new UnsupportedOperationException ( ) ; } else if ( v . isArrayValue ( ) ) { throw new UnsupportedOperationException ( ) ; } else { throw new UnsupportedOperationException ( ) ; } } } private ServerSocket serverSocket ; private MockProcess process ; private AtomicBoolean finished = new AtomicBoolean ( false ) ; public MockFluentd ( int port , MockProcess mockProcess ) throws IOException { serverSocket = new ServerSocket ( port ) ; process = mockProcess ; } public void run ( ) { while ( ! finished . get ( ) ) { try { final Socket socket = serverSocket . accept ( ) ; Runnable r = new Runnable ( ) { public void run ( ) { try { MessagePack msgpack = new MessagePack ( ) ; msgpack . register ( Event . class , MockEventTemplate . INSTANCE ) ; process . process ( msgpack , socket ) ; } catch ( IOException e ) { } } } ; new Thread ( r ) . start ( ) ; } catch ( IOException e ) { } } } public void close ( ) throws IOException { finished . set ( true ) ; if ( serverSocket != null ) { serverSocket . close ( ) ; } } } </s> |
<s> package org . fluentd . logger ; import static org . junit . Assert . assertEquals ; import java . io . BufferedInputStream ; import java . io . EOFException ; import java . io . IOException ; import java . net . Socket ; import java . util . ArrayList ; import java . util . HashMap ; import java . util . List ; import java . util . Map ; import java . util . Properties ; import org . fluentd . logger . sender . Event ; import org . fluentd . logger . sender . NullSender ; import org . fluentd . logger . util . MockFluentd ; import org . junit . Test ; import org . msgpack . MessagePack ; import org . msgpack . unpacker . Unpacker ; public class TestFluentLogger { @ Test public void testNormal01 ( ) throws Exception { int port = <NUM_LIT> ; String host = "<STR_LIT:localhost>" ; final List < Event > elist = new ArrayList < Event > ( ) ; MockFluentd fluentd = new MockFluentd ( port , new MockFluentd . MockProcess ( ) { public void process ( MessagePack msgpack , Socket socket ) throws IOException { BufferedInputStream in = new BufferedInputStream ( socket . getInputStream ( ) ) ; try { Unpacker unpacker = msgpack . createUnpacker ( in ) ; while ( true ) { Event e = unpacker . read ( Event . class ) ; elist . add ( e ) ; } } catch ( EOFException e ) { } } } ) ; fluentd . start ( ) ; FluentLogger logger = FluentLogger . getLogger ( "<STR_LIT>" , host , port ) ; { Map < String , Object > data = new HashMap < String , Object > ( ) ; data . put ( "<STR_LIT>" , "<STR_LIT>" ) ; data . put ( "<STR_LIT>" , "<STR_LIT>" ) ; logger . log ( "<STR_LIT>" , data ) ; } { Map < String , Object > data = new HashMap < String , Object > ( ) ; data . put ( "<STR_LIT>" , "<STR_LIT>" ) ; data . put ( "<STR_LIT>" , "<STR_LIT>" ) ; logger . log ( "<STR_LIT>" , data ) ; } logger . close ( ) ; fluentd . close ( ) ; Thread . sleep ( <NUM_LIT:1000> ) ; assertEquals ( <NUM_LIT:2> , elist . size ( ) ) ; assertEquals ( "<STR_LIT>" , elist . get ( <NUM_LIT:0> ) . tag ) ; assertEquals ( "<STR_LIT>" , elist . get ( <NUM_LIT:1> ) . tag ) ; } @ Test public void testNormal02 ( ) throws Exception { int port = <NUM_LIT> ; String host = "<STR_LIT:localhost>" ; final List [ ] elists = new List [ <NUM_LIT:2> ] ; elists [ <NUM_LIT:0> ] = new ArrayList < Event > ( ) ; elists [ <NUM_LIT:1> ] = new ArrayList < Event > ( ) ; MockFluentd fluentd = new MockFluentd ( port , new MockFluentd . MockProcess ( ) { public void process ( MessagePack msgpack , Socket socket ) throws IOException { BufferedInputStream in = new BufferedInputStream ( socket . getInputStream ( ) ) ; try { Unpacker unpacker = msgpack . createUnpacker ( in ) ; while ( true ) { Event e = unpacker . read ( Event . class ) ; if ( e . tag . startsWith ( "<STR_LIT>" ) ) { elists [ <NUM_LIT:0> ] . add ( e ) ; } else { elists [ <NUM_LIT:1> ] . add ( e ) ; } } } catch ( EOFException e ) { } } } ) ; fluentd . start ( ) ; FluentLogger [ ] loggers = new FluentLogger [ <NUM_LIT:2> ] ; int [ ] counts = new int [ <NUM_LIT:2> ] ; loggers [ <NUM_LIT:0> ] = FluentLogger . getLogger ( "<STR_LIT>" , host , port ) ; { for ( int i = <NUM_LIT:0> ; i < counts [ <NUM_LIT:0> ] ; i ++ ) { Map < String , Object > data = new HashMap < String , Object > ( ) ; data . put ( "<STR_LIT>" , "<STR_LIT>" ) ; data . put ( "<STR_LIT>" , "<STR_LIT>" ) ; loggers [ <NUM_LIT:0> ] . log ( "<STR_LIT>" , data ) ; } } loggers [ <NUM_LIT:1> ] = FluentLogger . getLogger ( "<STR_LIT>" , host , port ) ; { for ( int i = <NUM_LIT:0> ; i < counts [ <NUM_LIT:1> ] ; i ++ ) { Map < String , Object > data = new HashMap < String , Object > ( ) ; data . put ( "<STR_LIT>" , "<STR_LIT>" ) ; data . put ( "<STR_LIT>" , "<STR_LIT>" ) ; loggers [ <NUM_LIT:1> ] . log ( "<STR_LIT>" , data ) ; } } FluentLogger . closeAll ( ) ; fluentd . close ( ) ; Thread . sleep ( <NUM_LIT:1000> ) ; assertEquals ( counts [ <NUM_LIT:0> ] , elists [ <NUM_LIT:0> ] . size ( ) ) ; for ( Object obj : elists [ <NUM_LIT:0> ] ) { Event e = ( Event ) obj ; assertEquals ( "<STR_LIT>" , e . tag ) ; } assertEquals ( counts [ <NUM_LIT:1> ] , elists [ <NUM_LIT:1> ] . size ( ) ) ; for ( Object obj : elists [ <NUM_LIT:1> ] ) { Event e = ( Event ) obj ; assertEquals ( "<STR_LIT>" , e . tag ) ; } } @ Test public void testClose ( ) throws Exception { Properties props = System . getProperties ( ) ; props . setProperty ( Config . FLUENT_SENDER_CLASS , NullSender . class . getName ( ) ) ; FluentLogger . getLogger ( "<STR_LIT>" ) ; FluentLogger . getLogger ( "<STR_LIT>" ) ; FluentLogger . getLogger ( "<STR_LIT>" ) ; Map < String , FluentLogger > loggers ; { loggers = FluentLogger . getLoggers ( ) ; assertEquals ( <NUM_LIT:3> , loggers . size ( ) ) ; } FluentLogger . closeAll ( ) ; { loggers = FluentLogger . getLoggers ( ) ; assertEquals ( <NUM_LIT:0> , loggers . size ( ) ) ; } props . remove ( Config . FLUENT_SENDER_CLASS ) ; } } </s> |
<s> package org . fluentd . logger . sender ; import static org . junit . Assert . assertTrue ; import java . util . HashMap ; import java . util . Map ; import org . junit . Test ; public class TestNullSender { @ Test public void testNormal ( ) throws Exception { NullSender sender = new NullSender ( "<STR_LIT:localhost>" , <NUM_LIT> , <NUM_LIT:3> * <NUM_LIT:1000> , <NUM_LIT:1> * <NUM_LIT> * <NUM_LIT> ) ; { Map < String , Object > data = new HashMap < String , Object > ( ) ; assertTrue ( sender . emit ( "<STR_LIT:test>" , data ) ) ; } { Map < String , Object > data = new HashMap < String , Object > ( ) ; assertTrue ( sender . emit ( "<STR_LIT:test>" , System . currentTimeMillis ( ) / <NUM_LIT:1000> , data ) ) ; } sender . flush ( ) ; assertTrue ( true ) ; sender . close ( ) ; } } </s> |
<s> package org . fluentd . logger . sender ; import static org . junit . Assert . assertEquals ; import java . io . BufferedInputStream ; import java . io . EOFException ; import java . io . IOException ; import java . net . Socket ; import java . util . ArrayList ; import java . util . HashMap ; import java . util . List ; import java . util . Map ; import org . fluentd . logger . util . MockFluentd ; import org . junit . Test ; import org . msgpack . MessagePack ; import org . msgpack . unpacker . Unpacker ; public class TestRawSocketSender { @ Test public void testNormal01 ( ) throws Exception { int port = <NUM_LIT> ; final List < Event > elist = new ArrayList < Event > ( ) ; MockFluentd fluentd = new MockFluentd ( port , new MockFluentd . MockProcess ( ) { public void process ( MessagePack msgpack , Socket socket ) throws IOException { BufferedInputStream in = new BufferedInputStream ( socket . getInputStream ( ) ) ; try { Unpacker unpacker = msgpack . createUnpacker ( in ) ; while ( true ) { Event e = unpacker . read ( Event . class ) ; elist . add ( e ) ; } } catch ( EOFException e ) { } } } ) ; fluentd . start ( ) ; Sender sender = new RawSocketSender ( "<STR_LIT:localhost>" , port ) ; Map < String , Object > data = new HashMap < String , Object > ( ) ; data . put ( "<STR_LIT>" , "<STR_LIT>" ) ; data . put ( "<STR_LIT>" , "<STR_LIT>" ) ; sender . emit ( "<STR_LIT>" , data ) ; Map < String , Object > data2 = new HashMap < String , Object > ( ) ; data2 . put ( "<STR_LIT>" , "<STR_LIT>" ) ; data2 . put ( "<STR_LIT>" , "<STR_LIT>" ) ; sender . emit ( "<STR_LIT>" , data2 ) ; sender . close ( ) ; fluentd . close ( ) ; Thread . sleep ( <NUM_LIT:1000> ) ; assertEquals ( <NUM_LIT:2> , elist . size ( ) ) ; { Event e = elist . get ( <NUM_LIT:0> ) ; assertEquals ( "<STR_LIT>" , e . tag ) ; assertEquals ( "<STR_LIT>" , e . data . get ( "<STR_LIT>" ) ) ; assertEquals ( "<STR_LIT>" , e . data . get ( "<STR_LIT>" ) ) ; } { Event e = elist . get ( <NUM_LIT:1> ) ; assertEquals ( "<STR_LIT>" , e . tag ) ; assertEquals ( "<STR_LIT>" , e . data . get ( "<STR_LIT>" ) ) ; assertEquals ( "<STR_LIT>" , e . data . get ( "<STR_LIT>" ) ) ; } } @ Test public void testNormal02 ( ) throws Exception { int port = <NUM_LIT> ; final List < Event > elist = new ArrayList < Event > ( ) ; MockFluentd fluentd = new MockFluentd ( port , new MockFluentd . MockProcess ( ) { public void process ( MessagePack msgpack , Socket socket ) throws IOException { BufferedInputStream in = new BufferedInputStream ( socket . getInputStream ( ) ) ; try { Unpacker unpacker = msgpack . createUnpacker ( in ) ; while ( true ) { Event e = unpacker . read ( Event . class ) ; elist . add ( e ) ; } } catch ( EOFException e ) { } } } ) ; fluentd . start ( ) ; Sender sender = new RawSocketSender ( "<STR_LIT:localhost>" , port ) ; int count = <NUM_LIT> ; for ( int i = <NUM_LIT:0> ; i < count ; i ++ ) { String tag = "<STR_LIT>" ; Map < String , Object > record = new HashMap < String , Object > ( ) ; record . put ( "<STR_LIT:i>" , i ) ; record . put ( "<STR_LIT:n>" , "<STR_LIT>" + i ) ; sender . emit ( tag , record ) ; } sender . close ( ) ; fluentd . close ( ) ; Thread . sleep ( <NUM_LIT:1000> ) ; assertEquals ( count , elist . size ( ) ) ; } @ Test public void testNormal03 ( ) throws Exception { final MockFluentd [ ] fluentds = new MockFluentd [ <NUM_LIT:2> ] ; final List [ ] elists = new List [ <NUM_LIT:2> ] ; final int [ ] ports = new int [ <NUM_LIT:2> ] ; ports [ <NUM_LIT:0> ] = <NUM_LIT> ; elists [ <NUM_LIT:0> ] = new ArrayList < Event > ( ) ; fluentds [ <NUM_LIT:0> ] = new MockFluentd ( ports [ <NUM_LIT:0> ] , new MockFluentd . MockProcess ( ) { public void process ( MessagePack msgpack , Socket socket ) throws IOException { BufferedInputStream in = new BufferedInputStream ( socket . getInputStream ( ) ) ; try { Unpacker unpacker = msgpack . createUnpacker ( in ) ; while ( true ) { Event e = unpacker . read ( Event . class ) ; elists [ <NUM_LIT:0> ] . add ( e ) ; } } catch ( EOFException e ) { } } } ) ; fluentds [ <NUM_LIT:0> ] . start ( ) ; ports [ <NUM_LIT:1> ] = <NUM_LIT> ; elists [ <NUM_LIT:1> ] = new ArrayList < Event > ( ) ; fluentds [ <NUM_LIT:1> ] = new MockFluentd ( ports [ <NUM_LIT:1> ] , new MockFluentd . MockProcess ( ) { public void process ( MessagePack msgpack , Socket socket ) throws IOException { BufferedInputStream in = new BufferedInputStream ( socket . getInputStream ( ) ) ; try { Unpacker unpacker = msgpack . createUnpacker ( in ) ; while ( true ) { Event e = unpacker . read ( Event . class ) ; elists [ <NUM_LIT:1> ] . add ( e ) ; } } catch ( EOFException e ) { } } } ) ; fluentds [ <NUM_LIT:1> ] . start ( ) ; Sender [ ] senders = new Sender [ <NUM_LIT:2> ] ; int [ ] counts = new int [ <NUM_LIT:2> ] ; senders [ <NUM_LIT:0> ] = new RawSocketSender ( "<STR_LIT:localhost>" , ports [ <NUM_LIT:0> ] ) ; counts [ <NUM_LIT:0> ] = <NUM_LIT> ; for ( int i = <NUM_LIT:0> ; i < counts [ <NUM_LIT:0> ] ; i ++ ) { String tag = "<STR_LIT>" ; Map < String , Object > record = new HashMap < String , Object > ( ) ; record . put ( "<STR_LIT:i>" , i ) ; record . put ( "<STR_LIT:n>" , "<STR_LIT>" + i ) ; senders [ <NUM_LIT:0> ] . emit ( tag , record ) ; } senders [ <NUM_LIT:1> ] = new RawSocketSender ( "<STR_LIT:localhost>" , ports [ <NUM_LIT:1> ] ) ; counts [ <NUM_LIT:1> ] = <NUM_LIT> ; for ( int i = <NUM_LIT:0> ; i < counts [ <NUM_LIT:1> ] ; i ++ ) { String tag = "<STR_LIT>" ; Map < String , Object > record = new HashMap < String , Object > ( ) ; record . put ( "<STR_LIT:i>" , i ) ; record . put ( "<STR_LIT:n>" , "<STR_LIT>" + i ) ; senders [ <NUM_LIT:1> ] . emit ( tag , record ) ; } senders [ <NUM_LIT:0> ] . close ( ) ; senders [ <NUM_LIT:1> ] . close ( ) ; fluentds [ <NUM_LIT:0> ] . close ( ) ; fluentds [ <NUM_LIT:1> ] . close ( ) ; Thread . sleep ( <NUM_LIT:1000> ) ; assertEquals ( counts [ <NUM_LIT:0> ] , elists [ <NUM_LIT:0> ] . size ( ) ) ; assertEquals ( counts [ <NUM_LIT:1> ] , elists [ <NUM_LIT:1> ] . size ( ) ) ; } } </s> |
<s> package org . fluentd . logger . sender ; import static org . junit . Assert . assertArrayEquals ; import java . io . IOException ; import java . net . Socket ; import java . util . HashMap ; import java . util . Map ; import org . fluentd . logger . sender . RawSocketSender ; import org . fluentd . logger . sender . Sender ; import org . fluentd . logger . util . MockFluentd ; import org . fluentd . logger . util . MockFluentd . MockProcess ; import org . junit . Ignore ; import org . junit . Test ; import org . msgpack . MessagePack ; import org . msgpack . packer . BufferPacker ; public class TestSenderFluentdDownOperation { @ Test @ Ignore public void testFluentdDownOperation01 ( ) throws Exception { int port = <NUM_LIT> ; MessagePack msgpack = new MessagePack ( ) ; msgpack . register ( Event . class , Event . EventTemplate . INSTANCE ) ; BufferPacker packer = msgpack . createBufferPacker ( ) ; long timestamp = System . currentTimeMillis ( ) / <NUM_LIT:1000> ; Sender sender = new RawSocketSender ( "<STR_LIT:localhost>" , port ) ; Map < String , Object > data = new HashMap < String , Object > ( ) ; data . put ( "<STR_LIT>" , "<STR_LIT>" ) ; data . put ( "<STR_LIT>" , "<STR_LIT>" ) ; sender . emit ( "<STR_LIT>" , timestamp , data ) ; packer . write ( new Event ( "<STR_LIT>" , timestamp , data ) ) ; byte [ ] bytes1 = packer . toByteArray ( ) ; assertArrayEquals ( bytes1 , sender . getBuffer ( ) ) ; Map < String , Object > data2 = new HashMap < String , Object > ( ) ; data2 . put ( "<STR_LIT>" , "<STR_LIT>" ) ; data2 . put ( "<STR_LIT>" , "<STR_LIT>" ) ; sender . emit ( "<STR_LIT>" , timestamp , data2 ) ; packer . write ( new Event ( "<STR_LIT>" , timestamp , data2 ) ) ; byte [ ] bytes2 = packer . toByteArray ( ) ; assertArrayEquals ( bytes2 , sender . getBuffer ( ) ) ; sender . close ( ) ; } @ Ignore @ Test public void testFluentdDownOperation02 ( ) throws Exception { int port = <NUM_LIT> ; MessagePack msgpack = new MessagePack ( ) ; msgpack . register ( Event . class , Event . EventTemplate . INSTANCE ) ; BufferPacker packer = msgpack . createBufferPacker ( ) ; long timestamp = System . currentTimeMillis ( ) ; MockFluentd server = new MockFluentd ( port , new MockFluentd . MockProcess ( ) { public void process ( MessagePack msgpack , Socket socket ) throws IOException { System . out . println ( "<STR_LIT>" ) ; socket . close ( ) ; System . out . println ( "<STR_LIT>" ) ; } } ) ; server . start ( ) ; Sender sender = new RawSocketSender ( "<STR_LIT:localhost>" , port ) ; server . close ( ) ; Thread . sleep ( <NUM_LIT:1000> ) ; Map < String , Object > data = new HashMap < String , Object > ( ) ; data . put ( "<STR_LIT>" , "<STR_LIT>" ) ; data . put ( "<STR_LIT>" , "<STR_LIT>" ) ; for ( int i = <NUM_LIT:0> ; i < <NUM_LIT:3> ; ++ i ) { System . out . println ( "<STR_LIT>" ) ; sender . emit ( "<STR_LIT>" , data ) ; } packer . write ( new Event ( "<STR_LIT>" , timestamp , data ) ) ; byte [ ] bytes1 = packer . toByteArray ( ) ; assertArrayEquals ( bytes1 , sender . getBuffer ( ) ) ; Map < String , Object > data2 = new HashMap < String , Object > ( ) ; data2 . put ( "<STR_LIT>" , "<STR_LIT>" ) ; data2 . put ( "<STR_LIT>" , "<STR_LIT>" ) ; sender . emit ( "<STR_LIT>" , data2 ) ; packer . write ( new Event ( "<STR_LIT>" , timestamp , data2 ) ) ; byte [ ] bytes2 = packer . toByteArray ( ) ; assertArrayEquals ( bytes2 , sender . getBuffer ( ) ) ; sender . close ( ) ; } } </s> |
<s> package org . fluentd . logger ; import java . lang . reflect . Constructor ; import java . lang . reflect . InvocationTargetException ; import java . util . HashMap ; import java . util . Map ; import java . util . Properties ; import java . util . WeakHashMap ; import org . fluentd . logger . sender . RawSocketSender ; import org . fluentd . logger . sender . Sender ; public class FluentLogger { private static Map < String , FluentLogger > loggers = new WeakHashMap < String , FluentLogger > ( ) ; public static FluentLogger getLogger ( String tag ) { return getLogger ( tag , "<STR_LIT:localhost>" , <NUM_LIT> ) ; } public static FluentLogger getLogger ( String tag , String host , int port ) { return getLogger ( tag , host , port , <NUM_LIT:3> * <NUM_LIT:1000> , <NUM_LIT:1> * <NUM_LIT> * <NUM_LIT> ) ; } public static synchronized FluentLogger getLogger ( String tag , String host , int port , int timeout , int bufferCapacity ) { String key = String . format ( "<STR_LIT>" , new Object [ ] { tag , host , port , timeout , bufferCapacity } ) ; if ( loggers . containsKey ( key ) ) { return loggers . get ( key ) ; } else { Sender sender = null ; Properties props = System . getProperties ( ) ; if ( ! props . containsKey ( Config . FLUENT_SENDER_CLASS ) ) { sender = new RawSocketSender ( host , port , timeout , bufferCapacity ) ; } else { String senderClassName = props . getProperty ( Config . FLUENT_SENDER_CLASS ) ; try { sender = createSenderInstance ( senderClassName , new Object [ ] { host , port , timeout , bufferCapacity } ) ; } catch ( Exception e ) { throw new RuntimeException ( e ) ; } } FluentLogger logger = new FluentLogger ( tag , sender ) ; loggers . put ( key , logger ) ; return logger ; } } @ SuppressWarnings ( "<STR_LIT:unchecked>" ) private static Sender createSenderInstance ( final String className , final Object [ ] params ) throws ClassNotFoundException , SecurityException , NoSuchMethodException , IllegalArgumentException , InstantiationException , IllegalAccessException , InvocationTargetException { Class < Sender > cl = ( Class < Sender > ) FluentLogger . class . getClassLoader ( ) . loadClass ( className ) ; Constructor < Sender > cons = cl . getDeclaredConstructor ( new Class [ ] { String . class , int . class , int . class , int . class } ) ; return ( Sender ) cons . newInstance ( params ) ; } static Map < String , FluentLogger > getLoggers ( ) { return loggers ; } public static synchronized void closeAll ( ) { for ( FluentLogger logger : loggers . values ( ) ) { logger . close ( ) ; } loggers . clear ( ) ; } public static synchronized void flushAll ( ) { for ( FluentLogger logger : loggers . values ( ) ) { logger . flush ( ) ; } } protected String tagPrefix ; protected Sender sender ; protected FluentLogger ( ) { } protected FluentLogger ( String tag , Sender sender ) { tagPrefix = tag ; this . sender = sender ; } public boolean log ( String label , String key , Object value ) { return log ( label , key , value , <NUM_LIT:0> ) ; } public boolean log ( String label , String key , Object value , long timestamp ) { Map < String , Object > data = new HashMap < String , Object > ( ) ; data . put ( key , value ) ; return log ( label , data , timestamp ) ; } public boolean log ( String label , Map < String , Object > data ) { return log ( label , data , <NUM_LIT:0> ) ; } public boolean log ( String label , Map < String , Object > data , long timestamp ) { if ( timestamp != <NUM_LIT:0> ) { return sender . emit ( tagPrefix + "<STR_LIT:.>" + label , timestamp , data ) ; } else { return sender . emit ( tagPrefix + "<STR_LIT:.>" + label , data ) ; } } public void flush ( ) { sender . flush ( ) ; } public void close ( ) { if ( sender != null ) { sender . close ( ) ; sender = null ; } } public String getName ( ) { return String . format ( "<STR_LIT>" , tagPrefix , sender . getName ( ) ) ; } @ Override public String toString ( ) { return String . format ( "<STR_LIT>" , new Object [ ] { this . getClass ( ) . getName ( ) , tagPrefix , sender . toString ( ) } ) ; } @ Override public void finalize ( ) { if ( sender != null ) { sender . close ( ) ; } } } </s> |
<s> package org . fluentd . logger ; public interface Constants { String FLUENT_SENDER_CLASS = "<STR_LIT>" ; String FLUENT_RECONNECTOR_CLASS = "<STR_LIT>" ; } </s> |
<s> package org . fluentd . logger ; public class Config implements Constants { } </s> |
<s> package org . fluentd . logger . sender ; import java . io . BufferedOutputStream ; import java . io . IOException ; import java . net . InetSocketAddress ; import java . net . Socket ; import java . net . SocketAddress ; import java . nio . ByteBuffer ; import java . util . Map ; import java . util . logging . Level ; import org . msgpack . MessagePack ; public class RawSocketSender implements Sender { private static final java . util . logging . Logger LOG = java . util . logging . Logger . getLogger ( RawSocketSender . class . getName ( ) ) ; private MessagePack msgpack ; private SocketAddress server ; private Socket socket ; private int timeout ; private BufferedOutputStream out ; private ByteBuffer pendings ; private Reconnector reconnector ; private String name ; public RawSocketSender ( ) { this ( "<STR_LIT:localhost>" , <NUM_LIT> ) ; } public RawSocketSender ( String host , int port ) { this ( host , port , <NUM_LIT:3> * <NUM_LIT:1000> , <NUM_LIT:8> * <NUM_LIT> * <NUM_LIT> ) ; } public RawSocketSender ( String host , int port , int timeout , int bufferCapacity ) { msgpack = new MessagePack ( ) ; msgpack . register ( Event . class , Event . EventTemplate . INSTANCE ) ; pendings = ByteBuffer . allocate ( bufferCapacity ) ; server = new InetSocketAddress ( host , port ) ; reconnector = new ExponentialDelayReconnector ( ) ; name = String . format ( "<STR_LIT>" , host , port , timeout , bufferCapacity ) ; open ( ) ; } private void open ( ) { try { connect ( ) ; } catch ( IOException e ) { LOG . severe ( "<STR_LIT>" + server . toString ( ) ) ; LOG . severe ( "<STR_LIT>" ) ; e . printStackTrace ( ) ; close ( ) ; } } private void connect ( ) throws IOException { try { socket = new Socket ( ) ; socket . connect ( server ) ; socket . setSoTimeout ( timeout ) ; out = new BufferedOutputStream ( socket . getOutputStream ( ) ) ; reconnector . clearErrorHistory ( ) ; } catch ( IOException e ) { reconnector . addErrorHistory ( System . currentTimeMillis ( ) ) ; throw e ; } } private void reconnect ( ) throws IOException { if ( socket == null ) { connect ( ) ; } else if ( socket . isClosed ( ) || ( ! socket . isConnected ( ) ) ) { close ( ) ; connect ( ) ; } } public void close ( ) { if ( out != null ) { try { out . close ( ) ; } catch ( IOException e ) { } finally { out = null ; } } if ( socket != null ) { try { socket . close ( ) ; } catch ( IOException e ) { } finally { socket = null ; } } } public boolean emit ( String tag , Map < String , Object > data ) { return emit ( tag , System . currentTimeMillis ( ) / <NUM_LIT:1000> , data ) ; } public boolean emit ( String tag , long timestamp , Map < String , Object > data ) { return emit ( new Event ( tag , timestamp , data ) ) ; } protected boolean emit ( Event event ) { if ( LOG . isLoggable ( Level . FINE ) ) { LOG . fine ( String . format ( "<STR_LIT>" , new Object [ ] { event } ) ) ; } byte [ ] bytes = null ; try { bytes = msgpack . write ( event ) ; } catch ( IOException e ) { LOG . severe ( "<STR_LIT>" + event ) ; e . printStackTrace ( ) ; return false ; } return send ( bytes ) ; } private synchronized boolean send ( byte [ ] bytes ) { if ( pendings . position ( ) + bytes . length > pendings . capacity ( ) ) { LOG . severe ( "<STR_LIT>" + server . toString ( ) ) ; return false ; } pendings . put ( bytes ) ; if ( ! reconnector . enableReconnection ( System . currentTimeMillis ( ) ) ) { return true ; } flush ( ) ; return true ; } public synchronized void flush ( ) { try { reconnect ( ) ; out . write ( getBuffer ( ) ) ; out . flush ( ) ; clearBuffer ( ) ; } catch ( IOException e ) { LOG . throwing ( this . getClass ( ) . getName ( ) , "<STR_LIT>" , e ) ; } } public byte [ ] getBuffer ( ) { int len = pendings . position ( ) ; pendings . position ( <NUM_LIT:0> ) ; byte [ ] ret = new byte [ len ] ; pendings . get ( ret , <NUM_LIT:0> , len ) ; return ret ; } private void clearBuffer ( ) { pendings . clear ( ) ; } public String getName ( ) { return name ; } @ Override public String toString ( ) { return getName ( ) ; } } </s> |
<s> package org . fluentd . logger . sender ; import java . util . Map ; public class NullSender implements Sender { public NullSender ( String host , int port , int timeout , int bufferCapacity ) { } @ Override public boolean emit ( String tag , Map < String , Object > data ) { return emit ( tag , System . currentTimeMillis ( ) / <NUM_LIT:1000> , data ) ; } @ Override public boolean emit ( String tag , long timestamp , Map < String , Object > data ) { return true ; } @ Override public void flush ( ) { } @ Override public byte [ ] getBuffer ( ) { return new byte [ <NUM_LIT:0> ] ; } @ Override public void close ( ) { } public String getName ( ) { return "<STR_LIT:null>" ; } @ Override public String toString ( ) { return this . getClass ( ) . getName ( ) ; } } </s> |
<s> package org . fluentd . logger . sender ; import java . util . LinkedList ; public class ExponentialDelayReconnector implements Reconnector { private static final java . util . logging . Logger LOG = java . util . logging . Logger . getLogger ( ExponentialDelayReconnector . class . getName ( ) ) ; private double wait = <NUM_LIT> ; private double waitIncrRate = <NUM_LIT> ; private double waitMax = <NUM_LIT> ; private int waitMaxCount ; private LinkedList < Long > errorHistory ; public ExponentialDelayReconnector ( ) { waitMaxCount = getWaitMaxCount ( ) ; errorHistory = new LinkedList < Long > ( ) ; } private int getWaitMaxCount ( ) { double r = waitMax / wait ; for ( int j = <NUM_LIT:1> ; j <= <NUM_LIT:100> ; j ++ ) { if ( r < waitIncrRate ) { return j + <NUM_LIT:1> ; } r = r / waitIncrRate ; } return <NUM_LIT:100> ; } public void addErrorHistory ( long timestamp ) { errorHistory . addLast ( timestamp ) ; if ( errorHistory . size ( ) > waitMaxCount ) { errorHistory . removeFirst ( ) ; } } public void clearErrorHistory ( ) { errorHistory . clear ( ) ; } public boolean enableReconnection ( long timestamp ) { int size = errorHistory . size ( ) ; if ( size == <NUM_LIT:0> ) { return true ; } double suppressSec ; if ( size < waitMaxCount ) { suppressSec = wait * Math . pow ( waitIncrRate , size - <NUM_LIT:1> ) ; } else { suppressSec = waitMax ; } return ( ! ( timestamp - errorHistory . getLast ( ) < suppressSec ) ) ; } } </s> |
<s> package org . fluentd . logger . sender ; import java . io . IOException ; import java . util . Map ; import org . msgpack . MessageTypeException ; import org . msgpack . packer . Packer ; import org . msgpack . template . AbstractTemplate ; import org . msgpack . template . Templates ; import org . msgpack . unpacker . Unpacker ; public class Event { public String tag ; public long timestamp ; public Map < String , Object > data ; public Event ( ) { } public Event ( String tag , Map < String , Object > data ) { this ( tag , System . currentTimeMillis ( ) / <NUM_LIT:1000> , data ) ; } public Event ( String tag , long timestamp , Map < String , Object > data ) { this . tag = tag ; this . timestamp = timestamp ; this . data = data ; } @ Override public String toString ( ) { return String . format ( "<STR_LIT>" , tag , timestamp , data . toString ( ) ) ; } public static class EventTemplate extends AbstractTemplate < Event > { public static EventTemplate INSTANCE = new EventTemplate ( ) ; public void write ( Packer pk , Event v , boolean required ) throws IOException { if ( v == null ) { if ( required ) { throw new MessageTypeException ( "<STR_LIT>" ) ; } pk . writeNil ( ) ; return ; } pk . writeArrayBegin ( <NUM_LIT:3> ) ; { Templates . TString . write ( pk , v . tag , required ) ; Templates . TLong . write ( pk , v . timestamp , required ) ; pk . writeMapBegin ( v . data . size ( ) ) ; { for ( Map . Entry < String , Object > entry : v . data . entrySet ( ) ) { Templates . TString . write ( pk , entry . getKey ( ) , required ) ; try { pk . write ( entry . getValue ( ) ) ; } catch ( MessageTypeException e ) { String val = entry . getValue ( ) . toString ( ) ; Templates . TString . write ( pk , val , required ) ; } } } pk . writeMapEnd ( ) ; } pk . writeArrayEnd ( ) ; } public Event read ( Unpacker u , Event to , boolean required ) throws IOException { throw new UnsupportedOperationException ( "<STR_LIT>" ) ; } } } </s> |
<s> package org . fluentd . logger . sender ; public interface Reconnector { void clearErrorHistory ( ) ; void addErrorHistory ( long timestamp ) ; boolean enableReconnection ( long timestamp ) ; } </s> |
<s> package org . fluentd . logger . sender ; import java . util . Map ; public interface Sender { boolean emit ( String tag , Map < String , Object > data ) ; boolean emit ( String tag , long timestamp , Map < String , Object > data ) ; void flush ( ) ; public byte [ ] getBuffer ( ) ; public void close ( ) ; public String getName ( ) ; } </s> |
<s> package com . jhu . cvrg . portal . videodisplay . utility ; import java . io . IOException ; import java . util . List ; import javax . portlet . PortletRequest ; import javax . portlet . PortletPreferences ; import javax . portlet . ReadOnlyException ; import javax . portlet . ValidatorException ; import org . portletfaces . liferay . faces . context . LiferayFacesContext ; import org . portletfaces . liferay . faces . helper . LongHelper ; import com . liferay . portal . kernel . exception . PortalException ; import com . liferay . portal . kernel . exception . SystemException ; import com . liferay . portal . kernel . util . WebKeys ; import com . liferay . portal . model . Group ; import com . liferay . portal . model . User ; import com . liferay . portal . service . GroupLocalServiceUtil ; import com . liferay . portal . service . UserLocalServiceUtil ; import com . liferay . portal . theme . ThemeDisplay ; import com . liferay . portlet . documentlibrary . NoSuchFileEntryException ; import com . liferay . portlet . documentlibrary . model . DLFileEntry ; public class ResourceUtility { public static DLFileEntry getVideo ( long videoId ) { DLFileEntry video = null ; try { video = com . liferay . portlet . documentlibrary . service . DLFileEntryLocalServiceUtil . getFileEntry ( Long . valueOf ( videoId ) ) ; } catch ( NoSuchFileEntryException e ) { if ( videoId != <NUM_LIT> ) printErrorMessage ( "<STR_LIT>" ) ; } catch ( PortalException e ) { printErrorMessage ( "<STR_LIT>" ) ; e . printStackTrace ( ) ; } catch ( SystemException e ) { printErrorMessage ( "<STR_LIT>" ) ; e . printStackTrace ( ) ; } return video ; } public static String getControlType ( ) { LiferayFacesContext liferayFacesContext = LiferayFacesContext . getInstance ( ) ; PortletPreferences prefs = liferayFacesContext . getPortletPreferences ( ) ; return prefs . getValue ( "<STR_LIT>" , "<STR_LIT:1>" ) ; } public static String getStoredVideo ( ) { LiferayFacesContext liferayFacesContext = LiferayFacesContext . getInstance ( ) ; PortletPreferences prefs = liferayFacesContext . getPortletPreferences ( ) ; return prefs . getValue ( "<STR_LIT:default>" , "<STR_LIT:0>" ) ; } public static String getStoredFolder ( ) { LiferayFacesContext liferayFacesContext = LiferayFacesContext . getInstance ( ) ; PortletPreferences prefs = liferayFacesContext . getPortletPreferences ( ) ; return prefs . getValue ( "<STR_LIT>" , "<STR_LIT:0>" ) ; } public static String getStoredHostname ( ) { LiferayFacesContext liferayFacesContext = LiferayFacesContext . getInstance ( ) ; PortletPreferences prefs = liferayFacesContext . getPortletPreferences ( ) ; return prefs . getValue ( "<STR_LIT>" , "<STR_LIT>" ) ; } public static boolean getFullScreen ( ) { LiferayFacesContext liferayFacesContext = LiferayFacesContext . getInstance ( ) ; PortletPreferences prefs = liferayFacesContext . getPortletPreferences ( ) ; return prefs . getValue ( "<STR_LIT>" , "<STR_LIT:false>" ) . equals ( "<STR_LIT:true>" ) ; } public static void savePreferences ( String folder , String video , String hostname , String controlType , boolean fullscreen ) { LiferayFacesContext liferayFacesContext = LiferayFacesContext . getInstance ( ) ; PortletPreferences prefs = liferayFacesContext . getPortletPreferences ( ) ; try { prefs . setValue ( "<STR_LIT>" , controlType ) ; prefs . setValue ( "<STR_LIT>" , folder ) ; prefs . setValue ( "<STR_LIT:default>" , video ) ; prefs . setValue ( "<STR_LIT>" , hostname ) ; prefs . setValue ( "<STR_LIT>" , String . valueOf ( fullscreen ) ) ; prefs . store ( ) ; } catch ( ReadOnlyException e ) { printErrorMessage ( "<STR_LIT>" ) ; e . printStackTrace ( ) ; } catch ( ValidatorException e ) { printErrorMessage ( "<STR_LIT>" ) ; e . printStackTrace ( ) ; } catch ( IOException e ) { printErrorMessage ( "<STR_LIT>" ) ; e . printStackTrace ( ) ; } } public static void printErrorMessage ( String source ) { System . err . println ( "<STR_LIT>" + source + "<STR_LIT>" ) ; } public static long getIdParameter ( String param ) { LiferayFacesContext liferayFacesContext = LiferayFacesContext . getInstance ( ) ; return LongHelper . toLong ( liferayFacesContext . getExternalContext ( ) . getRequestParameterMap ( ) . get ( param ) , <NUM_LIT> ) ; } public static User getUser ( long userId ) { User user = null ; try { user = UserLocalServiceUtil . getUser ( userId ) ; } catch ( PortalException e ) { printErrorMessage ( "<STR_LIT>" ) ; e . printStackTrace ( ) ; } catch ( SystemException e ) { printErrorMessage ( "<STR_LIT>" ) ; e . printStackTrace ( ) ; } return user ; } public static long getCurrentGroupId ( ) { LiferayFacesContext liferayFacesContext = LiferayFacesContext . getInstance ( ) ; PortletRequest request = ( PortletRequest ) liferayFacesContext . getExternalContext ( ) . getRequest ( ) ; ThemeDisplay themeDisplay = ( ThemeDisplay ) request . getAttribute ( WebKeys . THEME_DISPLAY ) ; return themeDisplay . getLayout ( ) . getGroupId ( ) ; } public static User getCurrentUser ( ) { LiferayFacesContext liferayFacesContext = LiferayFacesContext . getInstance ( ) ; User currentUser = null ; try { currentUser = UserLocalServiceUtil . getUser ( Long . parseLong ( liferayFacesContext . getPortletRequest ( ) . getRemoteUser ( ) ) ) ; } catch ( NumberFormatException e ) { printErrorMessage ( "<STR_LIT>" ) ; e . printStackTrace ( ) ; } catch ( PortalException e ) { printErrorMessage ( "<STR_LIT>" ) ; e . printStackTrace ( ) ; } catch ( SystemException e ) { printErrorMessage ( "<STR_LIT>" ) ; e . printStackTrace ( ) ; } return currentUser ; } public static long getGroupId ( String communityName ) { long groupId = <NUM_LIT> ; List < Group > groupList ; try { groupList = GroupLocalServiceUtil . getGroups ( <NUM_LIT:0> , GroupLocalServiceUtil . getGroupsCount ( ) ) ; ; for ( Group group : groupList ) { if ( group . getName ( ) . equals ( communityName ) ) { groupId = group . getGroupId ( ) ; } } } catch ( SystemException e ) { printErrorMessage ( "<STR_LIT>" ) ; e . printStackTrace ( ) ; } return groupId ; } } </s> |
<s> package com . jhu . cvrg . portal . videodisplay . backing ; import javax . faces . bean . ManagedBean ; import javax . faces . bean . ManagedProperty ; import javax . faces . bean . ViewScoped ; import javax . faces . event . ActionEvent ; import javax . faces . event . PhaseId ; import javax . faces . event . ValueChangeEvent ; import javax . portlet . GenericPortlet ; import com . jhu . cvrg . portal . videodisplay . model . VideoList ; import com . jhu . cvrg . portal . videodisplay . utility . ResourceUtility ; import com . liferay . portlet . documentlibrary . model . DLFileEntry ; @ ManagedBean ( name = "<STR_LIT>" ) @ ViewScoped public class VideoDisplay extends GenericPortlet { private String selectedFolder , selectedVideo ; private String source ; private String uuid , hostname , filename ; private long groupId ; private boolean noVideo , maximized , control ; private int width , height ; private static int MAX_WIDTH = <NUM_LIT:1000> ; private static int MAX_HEIGHT = <NUM_LIT> ; private static int MIN_WIDTH = <NUM_LIT> ; private static int MIN_HEIGHT = <NUM_LIT> ; @ ManagedProperty ( name = "<STR_LIT>" , value = "<STR_LIT>" ) private VideoList videoList ; public VideoDisplay ( ) { selectedFolder = ResourceUtility . getStoredFolder ( ) ; selectedVideo = ResourceUtility . getStoredVideo ( ) ; hostname = ResourceUtility . getStoredHostname ( ) ; if ( selectedVideo . equals ( "<STR_LIT:0>" ) ) noVideo = true ; else noVideo = false ; if ( this . isMaximized ( ) ) { width = MAX_WIDTH ; height = MAX_HEIGHT ; } else { if ( ResourceUtility . getFullScreen ( ) ) { width = MAX_WIDTH ; height = MAX_HEIGHT ; } else { width = MIN_WIDTH ; height = MIN_HEIGHT ; } } if ( ResourceUtility . getControlType ( ) . equals ( "<STR_LIT:1>" ) ) { control = true ; } else { control = false ; } } public void back ( ActionEvent event ) { selectedVideo = videoList . getPreviousVideo ( selectedVideo ) ; } public void forward ( ActionEvent event ) { selectedVideo = videoList . getNextVideo ( selectedVideo ) ; } public void changedVideoEvent ( ValueChangeEvent event ) { PhaseId phaseId = event . getPhaseId ( ) ; if ( phaseId . equals ( PhaseId . ANY_PHASE ) ) { event . setPhaseId ( PhaseId . UPDATE_MODEL_VALUES ) ; event . queue ( ) ; } else if ( phaseId . equals ( PhaseId . UPDATE_MODEL_VALUES ) ) { if ( ! selectedVideo . equals ( "<STR_LIT:0>" ) ) noVideo = false ; else noVideo = true ; setVideoURL ( selectedVideo ) ; } } public String getHostname ( ) { return hostname ; } public void setHostname ( String hostname ) { this . hostname = hostname ; } public void setSelectedFolder ( String selectedFolder ) { this . selectedFolder = selectedFolder ; } public String getSelectedFolder ( ) { if ( ! selectedFolder . equals ( "<STR_LIT:0>" ) ) { return selectedFolder ; } else { return "<STR_LIT>" ; } } private void setVideoURL ( String selectedVideo ) { DLFileEntry video = null ; if ( ! noVideo && ! selectedVideo . equals ( "<STR_LIT:0>" ) ) { video = ResourceUtility . getVideo ( Long . valueOf ( selectedVideo ) ) ; if ( video != null ) { uuid = video . getUuid ( ) ; filename = video . getTitle ( ) ; groupId = video . getGroupId ( ) ; noVideo = false ; } } } public void setSelectedVideo ( String selectedVideo ) { this . selectedVideo = selectedVideo ; } public String getSelectedVideo ( ) { return selectedVideo ; } public void setSource ( String source ) { this . source = source ; } public String getSource ( ) { if ( ! selectedVideo . equals ( "<STR_LIT:0>" ) && ! selectedVideo . equals ( "<STR_LIT>" ) ) { setVideoURL ( selectedVideo ) ; source = "<STR_LIT:http://>" + hostname + "<STR_LIT>" + groupId + "<STR_LIT:/>" + uuid ; return source ; } else { return "<STR_LIT>" ; } } public void setNoVideo ( boolean noVideo ) { this . noVideo = noVideo ; } public boolean isNoVideo ( ) { return noVideo ; } public void setMaximized ( boolean maximized ) { if ( maximized || ResourceUtility . getFullScreen ( ) ) { width = MAX_WIDTH ; height = MAX_HEIGHT ; } else { width = MIN_WIDTH ; height = MIN_HEIGHT ; } this . maximized = maximized ; } public boolean isMaximized ( ) { return maximized ; } public void setWidth ( int width ) { this . width = width ; } public int getWidth ( ) { return width ; } public void setHeight ( int height ) { this . height = height ; } public int getHeight ( ) { return height ; } public String getFilename ( ) { return filename ; } public void setFilename ( String filename ) { this . filename = filename ; } public VideoList getVideoList ( ) { return videoList ; } public void setVideoList ( VideoList videoList ) { this . videoList = videoList ; } public void setControl ( boolean control ) { this . control = control ; } public boolean isControl ( ) { return control ; } } </s> |
<s> package com . jhu . cvrg . portal . videodisplay . backing ; import java . util . ArrayList ; import javax . faces . bean . ManagedBean ; import javax . faces . bean . ViewScoped ; import javax . faces . event . ActionEvent ; import javax . faces . event . PhaseId ; import javax . faces . event . ValueChangeEvent ; import javax . faces . model . SelectItem ; import org . portletfaces . liferay . faces . context . LiferayFacesContext ; import com . jhu . cvrg . portal . videodisplay . model . FolderList ; import com . jhu . cvrg . portal . videodisplay . model . VideoList ; import com . jhu . cvrg . portal . videodisplay . utility . ResourceUtility ; @ ManagedBean ( name = "<STR_LIT>" ) @ ViewScoped public class PreferencesBacking { private String saved ; private String selectedFolder , selectedVideo , hostname ; private String selectedControlType ; private FolderList folderList ; private VideoList videoList ; LiferayFacesContext liferayFacesContext = LiferayFacesContext . getInstance ( ) ; private boolean fullscreen = false ; public PreferencesBacking ( ) { selectedControlType = ResourceUtility . getControlType ( ) ; selectedFolder = ResourceUtility . getStoredFolder ( ) ; selectedVideo = ResourceUtility . getStoredVideo ( ) ; hostname = ResourceUtility . getStoredHostname ( ) ; fullscreen = ResourceUtility . getFullScreen ( ) ; } public boolean isFullscreen ( ) { return fullscreen ; } public void setFullscreen ( boolean fullscreen ) { this . fullscreen = fullscreen ; } public void apply ( ActionEvent event ) { ResourceUtility . savePreferences ( selectedFolder , selectedVideo , hostname , selectedControlType , fullscreen ) ; setSaved ( "<STR_LIT>" ) ; } public void folderChangedEvent ( ValueChangeEvent event ) { PhaseId phaseId = event . getPhaseId ( ) ; if ( phaseId . equals ( PhaseId . ANY_PHASE ) ) { event . setPhaseId ( PhaseId . UPDATE_MODEL_VALUES ) ; event . queue ( ) ; } else if ( phaseId . equals ( PhaseId . UPDATE_MODEL_VALUES ) ) { videoList . refresh ( selectedFolder ) ; saved = "<STR_LIT>" ; } } public ArrayList < SelectItem > getControls ( ) { ArrayList < SelectItem > controls = new ArrayList < SelectItem > ( ) ; controls . add ( new SelectItem ( <NUM_LIT:1> , "<STR_LIT>" ) ) ; controls . add ( new SelectItem ( <NUM_LIT:2> , "<STR_LIT>" ) ) ; return controls ; } public void changedHostname ( ValueChangeEvent event ) { saved = "<STR_LIT>" ; } public void setSaved ( String saved ) { this . saved = saved ; } public String getSaved ( ) { return saved ; } public String getSelectedFolder ( ) { return selectedFolder ; } public void setSelectedFolder ( String selectedFolder ) { this . selectedFolder = selectedFolder ; } public String getSelectedVideo ( ) { return selectedVideo ; } public void setSelectedVideo ( String selectedVideo ) { this . selectedVideo = selectedVideo ; } public String getHostname ( ) { return hostname ; } public void setHostname ( String hostname ) { this . hostname = hostname ; } public void setFolderList ( FolderList folderList ) { this . folderList = folderList ; } public FolderList getFolderList ( ) { return folderList ; } public VideoList getVideoList ( ) { return videoList ; } public void setVideoList ( VideoList videoList ) { this . videoList = videoList ; } public void setSelectedControlType ( String selectedControlType ) { this . selectedControlType = selectedControlType ; } public String getSelectedControlType ( ) { return selectedControlType ; } } </s> |
<s> package com . jhu . cvrg . portal . videodisplay . model ; import java . util . ArrayList ; import java . util . Collections ; import java . util . Comparator ; import java . util . List ; import javax . faces . bean . ManagedBean ; import javax . faces . bean . ViewScoped ; import javax . faces . model . SelectItem ; import com . jhu . cvrg . portal . videodisplay . utility . ResourceUtility ; import com . liferay . portlet . documentlibrary . model . DLFileEntry ; @ ManagedBean ( name = "<STR_LIT>" ) @ ViewScoped public class VideoList { private ArrayList < SelectItem > videos ; private String selectedVideo ; public void refresh ( String selectedFolder ) { List < DLFileEntry > videoSet ; long groupId = <NUM_LIT> ; long lngSelectedFolder = Long . valueOf ( selectedFolder ) ; groupId = ResourceUtility . getCurrentGroupId ( ) ; try { videoSet = com . liferay . portlet . documentlibrary . service . DLFileEntryLocalServiceUtil . getFileEntries ( groupId , lngSelectedFolder ) ; videos = new ArrayList < SelectItem > ( ) ; for ( DLFileEntry video : videoSet ) { SelectItem item = new SelectItem ( video . getFileEntryId ( ) , video . getTitle ( ) ) ; videos . add ( item ) ; } sortAlphabetically ( videos ) ; } catch ( com . liferay . portal . kernel . exception . SystemException e ) { ResourceUtility . printErrorMessage ( "<STR_LIT>" ) ; e . printStackTrace ( ) ; } } public String getNextVideo ( String currentVideo ) { int index = <NUM_LIT:0> ; for ( SelectItem item : videos ) { if ( item . getValue ( ) . toString ( ) . equals ( currentVideo ) ) { index = videos . indexOf ( item ) ; if ( index == ( videos . size ( ) - <NUM_LIT:1> ) ) { index = <NUM_LIT:0> ; } else { index ++ ; } } } return videos . get ( index ) . getValue ( ) . toString ( ) ; } public String getPreviousVideo ( String currentVideo ) { int index = <NUM_LIT:0> ; for ( SelectItem item : videos ) { if ( item . getValue ( ) . toString ( ) . equals ( currentVideo ) ) { index = videos . indexOf ( item ) ; if ( index == <NUM_LIT:0> ) { index = ( videos . size ( ) - <NUM_LIT:1> ) ; } else { index -- ; } } } return videos . get ( index ) . getValue ( ) . toString ( ) ; } @ SuppressWarnings ( { "<STR_LIT:unchecked>" , "<STR_LIT:rawtypes>" } ) private void sortAlphabetically ( ArrayList < SelectItem > videos ) { Collections . sort ( videos , new Comparator ( ) { public int compare ( Object o1 , Object o2 ) { SelectItem p1 = ( SelectItem ) o1 ; SelectItem p2 = ( SelectItem ) o2 ; return p1 . getLabel ( ) . compareToIgnoreCase ( p2 . getLabel ( ) ) ; } } ) ; } public void refresh ( ) { refresh ( "<STR_LIT:0>" ) ; } public void setSelectedVideo ( String selectedVideo ) { this . selectedVideo = selectedVideo ; } public String getSelectedVideo ( ) { return selectedVideo ; } public ArrayList < SelectItem > getVideos ( ) { return videos ; } } </s> |
<s> package com . jhu . cvrg . portal . videodisplay . model ; import java . util . ArrayList ; import java . util . List ; import javax . faces . bean . ManagedBean ; import javax . faces . bean . ViewScoped ; import javax . faces . model . SelectItem ; import com . jhu . cvrg . portal . videodisplay . utility . ResourceUtility ; import com . liferay . portal . util . PortalUtil ; import com . liferay . portlet . documentlibrary . model . DLFolder ; @ ManagedBean ( name = "<STR_LIT>" ) @ ViewScoped public class FolderList { private ArrayList < SelectItem > folders ; public FolderList ( ) { List < DLFolder > folderSet ; long companyId = PortalUtil . getDefaultCompanyId ( ) ; try { folderSet = com . liferay . portlet . documentlibrary . service . DLFolderLocalServiceUtil . getFolders ( companyId ) ; folders = new ArrayList < SelectItem > ( ) ; for ( DLFolder folder : folderSet ) { SelectItem item = new SelectItem ( folder . getFolderId ( ) , folder . getName ( ) ) ; folders . add ( item ) ; } } catch ( com . liferay . portal . kernel . exception . SystemException e ) { ResourceUtility . printErrorMessage ( "<STR_LIT>" ) ; e . printStackTrace ( ) ; } } public ArrayList < SelectItem > getFolders ( ) { return folders ; } } </s> |
<s> package com . jhu . cvrg . portal . videodisplay . listener ; import javax . faces . context . FacesContext ; import javax . faces . event . PhaseEvent ; import javax . faces . event . PhaseId ; import javax . faces . event . PhaseListener ; import javax . faces . render . ResponseStateManager ; import javax . portlet . PortletRequest ; import javax . portlet . WindowState ; import org . portletfaces . liferay . faces . context . LiferayFacesContext ; import com . jhu . cvrg . portal . videodisplay . backing . PreferencesBacking ; import com . jhu . cvrg . portal . videodisplay . backing . VideoDisplay ; import com . jhu . cvrg . portal . videodisplay . model . VideoList ; import com . jhu . cvrg . portal . videodisplay . utility . ResourceUtility ; public class VideoPhaseListener implements PhaseListener { private static final long serialVersionUID = <NUM_LIT:1L> ; private static LiferayFacesContext liferayFacesContext ; VideoList videoList ; public void afterPhase ( PhaseEvent pe ) { } public void beforePhase ( PhaseEvent pe ) { liferayFacesContext = LiferayFacesContext . getInstance ( ) ; if ( pe . getPhaseId ( ) == PhaseId . RENDER_RESPONSE ) { VideoDisplay videoDisplay = ( VideoDisplay ) liferayFacesContext . getApplication ( ) . getELResolver ( ) . getValue ( liferayFacesContext . getELContext ( ) , null , "<STR_LIT>" ) ; PreferencesBacking preferencesBacking = ( PreferencesBacking ) liferayFacesContext . getApplication ( ) . getELResolver ( ) . getValue ( liferayFacesContext . getELContext ( ) , null , "<STR_LIT>" ) ; VideoList videoList = ( VideoList ) liferayFacesContext . getApplication ( ) . getELResolver ( ) . getValue ( liferayFacesContext . getELContext ( ) , null , "<STR_LIT>" ) ; videoList . refresh ( preferencesBacking . getSelectedFolder ( ) ) ; PortletRequest portletRequest = liferayFacesContext . getPortletRequest ( ) ; ResponseStateManager rsm = FacesContext . getCurrentInstance ( ) . getRenderKit ( ) . getResponseStateManager ( ) ; if ( videoDisplay != null ) { if ( ! rsm . isPostback ( liferayFacesContext ) ) { videoDisplay . setSelectedVideo ( ResourceUtility . getStoredVideo ( ) ) ; } videoDisplay . setMaximized ( ( portletRequest . getWindowState ( ) . equals ( WindowState . MAXIMIZED ) ) ) ; } } } public PhaseId getPhaseId ( ) { return PhaseId . ANY_PHASE ; } } </s> |
<s> package org . metatype ; import java . lang . annotation . Annotation ; import java . lang . reflect . Method ; import java . util . ArrayList ; import java . util . List ; import java . util . Map ; public class MetaAnnotatedMethod extends MetaAnnotatedObject < Method > implements AnnotatedMethod < Method > { private final Annotation [ ] [ ] parameterAnnotations ; public MetaAnnotatedMethod ( Method method ) { super ( method , unroll ( method ) ) ; this . parameterAnnotations = unrollParameters ( method . getParameterAnnotations ( ) ) ; } public Annotation [ ] getDeclaredAnnotations ( ) { return target . getDeclaredAnnotations ( ) ; } public Annotation [ ] [ ] getParameterAnnotations ( ) { return parameterAnnotations ; } public Class < ? > getDeclaringClass ( ) { return target . getDeclaringClass ( ) ; } public String getName ( ) { return target . getName ( ) ; } public int getModifiers ( ) { return target . getModifiers ( ) ; } public Class < ? > [ ] getParameterTypes ( ) { return target . getParameterTypes ( ) ; } public java . lang . reflect . Type [ ] getGenericParameterTypes ( ) { return target . getGenericParameterTypes ( ) ; } public Class < ? > [ ] getExceptionTypes ( ) { return target . getExceptionTypes ( ) ; } public java . lang . reflect . Type [ ] getGenericExceptionTypes ( ) { return target . getGenericExceptionTypes ( ) ; } public String toGenericString ( ) { return target . toGenericString ( ) ; } public boolean isVarArgs ( ) { return target . isVarArgs ( ) ; } public boolean isSynthetic ( ) { return target . isSynthetic ( ) ; } } </s> |
<s> package org . metatype ; import java . lang . annotation . Annotation ; import java . lang . reflect . Constructor ; public class MetaAnnotatedConstructor < T > extends MetaAnnotatedObject < Constructor < T > > implements AnnotatedMethod < Constructor < T > > { private Annotation [ ] [ ] parameterAnnotations ; public MetaAnnotatedConstructor ( Constructor < T > target ) { super ( target , unroll ( target ) ) ; this . parameterAnnotations = unrollParameters ( target . getParameterAnnotations ( ) ) ; } public Annotation [ ] getDeclaredAnnotations ( ) { return get ( ) . getDeclaredAnnotations ( ) ; } public Annotation [ ] [ ] getParameterAnnotations ( ) { return parameterAnnotations ; } public Class < ? > getDeclaringClass ( ) { return get ( ) . getDeclaringClass ( ) ; } public String getName ( ) { return get ( ) . getName ( ) ; } public int getModifiers ( ) { return get ( ) . getModifiers ( ) ; } public Class < ? > [ ] getParameterTypes ( ) { return get ( ) . getParameterTypes ( ) ; } public java . lang . reflect . Type [ ] getGenericParameterTypes ( ) { return get ( ) . getGenericParameterTypes ( ) ; } public Class < ? > [ ] getExceptionTypes ( ) { return get ( ) . getExceptionTypes ( ) ; } public java . lang . reflect . Type [ ] getGenericExceptionTypes ( ) { return get ( ) . getGenericExceptionTypes ( ) ; } public String toGenericString ( ) { return get ( ) . toGenericString ( ) ; } public boolean isVarArgs ( ) { return get ( ) . isVarArgs ( ) ; } public boolean isSynthetic ( ) { return get ( ) . isSynthetic ( ) ; } } </s> |
<s> package org . metatype ; import java . lang . annotation . Annotation ; import java . lang . reflect . Field ; public class MetaAnnotatedField extends MetaAnnotatedObject < Field > implements AnnotatedMember < Field > { public MetaAnnotatedField ( Field field ) { super ( field , unroll ( field ) ) ; } public Annotation [ ] getDeclaredAnnotations ( ) { return get ( ) . getDeclaredAnnotations ( ) ; } public Class < ? > getDeclaringClass ( ) { return get ( ) . getDeclaringClass ( ) ; } public String getName ( ) { return get ( ) . getName ( ) ; } public int getModifiers ( ) { return get ( ) . getModifiers ( ) ; } public boolean isSynthetic ( ) { return get ( ) . isSynthetic ( ) ; } } </s> |
<s> package org . metatype ; import java . lang . annotation . Annotation ; import java . util . ArrayList ; import java . util . List ; public class MetaAnnotation < T extends Annotation > { private final T annotation ; private final int depth ; private final List < MetaAnnotation < T > > conflicts = new ArrayList < MetaAnnotation < T > > ( ) ; MetaAnnotation ( T annotation , int depth ) { this . annotation = annotation ; this . depth = depth ; } public T get ( ) { return annotation ; } public int getDepth ( ) { return depth ; } public List < MetaAnnotation < T > > getConflicts ( ) { return conflicts ; } } </s> |
<s> package org . metatype ; import java . lang . reflect . Member ; public interface AnnotatedMember < T > extends Annotated < T > , Member { } </s> |
<s> package org . metatype ; import java . io . InputStream ; import java . lang . annotation . Annotation ; import java . lang . reflect . Constructor ; import java . lang . reflect . Field ; import java . lang . reflect . Method ; import java . lang . reflect . Type ; import java . lang . reflect . TypeVariable ; import java . net . URL ; import java . security . ProtectionDomain ; public class MetaAnnotatedClass < T > extends MetaAnnotatedObject < Class < T > > { public MetaAnnotatedClass ( Class < T > clazz ) { super ( clazz , unroll ( clazz ) ) ; } public Annotation [ ] getDeclaredAnnotations ( ) { return target . getDeclaredAnnotations ( ) ; } public MetaAnnotatedClass < ? > forName ( String className ) throws ClassNotFoundException { return to ( target . forName ( className ) ) ; } private MetaAnnotatedClass < ? > to ( Class < ? > clazz ) { return new MetaAnnotatedClass ( clazz ) ; } public MetaAnnotatedClass < ? > forName ( String name , boolean initialize , ClassLoader loader ) throws ClassNotFoundException { return to ( target . forName ( name , initialize , loader ) ) ; } public T newInstance ( ) throws InstantiationException , IllegalAccessException { return target . newInstance ( ) ; } public boolean isInstance ( Object obj ) { return target . isInstance ( obj ) ; } public boolean isAssignableFrom ( Class < ? > cls ) { return target . isAssignableFrom ( cls ) ; } public boolean isInterface ( ) { return target . isInterface ( ) ; } public boolean isArray ( ) { return target . isArray ( ) ; } public boolean isPrimitive ( ) { return target . isPrimitive ( ) ; } public boolean isAnnotation ( ) { return target . isAnnotation ( ) ; } public boolean isSynthetic ( ) { return target . isSynthetic ( ) ; } public String getName ( ) { return target . getName ( ) ; } public ClassLoader getClassLoader ( ) { return target . getClassLoader ( ) ; } public TypeVariable < Class < T > > [ ] getTypeParameters ( ) { return target . getTypeParameters ( ) ; } public MetaAnnotatedClass < ? super T > getSuperclass ( ) { return new MetaAnnotatedClass ( target . getSuperclass ( ) ) ; } public Type getGenericSuperclass ( ) { return target . getGenericSuperclass ( ) ; } public Package getPackage ( ) { return target . getPackage ( ) ; } public MetaAnnotatedClass < ? > [ ] getInterfaces ( ) { return to ( target . getInterfaces ( ) ) ; } public Type [ ] getGenericInterfaces ( ) { return target . getGenericInterfaces ( ) ; } public MetaAnnotatedClass < ? > getComponentType ( ) { return to ( target . getComponentType ( ) ) ; } public int getModifiers ( ) { return target . getModifiers ( ) ; } public Object [ ] getSigners ( ) { return target . getSigners ( ) ; } public MetaAnnotatedMethod getEnclosingMethod ( ) { return to ( target . getEnclosingMethod ( ) ) ; } public MetaAnnotatedConstructor < ? > getEnclosingConstructor ( ) { return to ( target . getEnclosingConstructor ( ) ) ; } public MetaAnnotatedClass < ? > getDeclaringClass ( ) { return to ( target . getDeclaringClass ( ) ) ; } public MetaAnnotatedClass < ? > getEnclosingClass ( ) { return to ( target . getEnclosingClass ( ) ) ; } public String getSimpleName ( ) { return target . getSimpleName ( ) ; } public String getCanonicalName ( ) { return target . getCanonicalName ( ) ; } public boolean isAnonymousClass ( ) { return target . isAnonymousClass ( ) ; } public boolean isLocalClass ( ) { return target . isLocalClass ( ) ; } public boolean isMemberClass ( ) { return target . isMemberClass ( ) ; } public MetaAnnotatedClass < ? > [ ] getClasses ( ) { return to ( target . getClasses ( ) ) ; } public MetaAnnotatedField [ ] getFields ( ) throws SecurityException { return to ( target . getFields ( ) ) ; } public MetaAnnotatedMethod [ ] getMethods ( ) throws SecurityException { return to ( target . getMethods ( ) ) ; } public MetaAnnotatedConstructor < ? > [ ] getConstructors ( ) throws SecurityException { return to ( target . getConstructors ( ) ) ; } public MetaAnnotatedField getField ( String name ) throws NoSuchFieldException , SecurityException { return to ( target . getField ( name ) ) ; } public MetaAnnotatedMethod getMethod ( String name , Class < ? > ... parameterTypes ) throws NoSuchMethodException , SecurityException { return to ( target . getMethod ( name , parameterTypes ) ) ; } public MetaAnnotatedConstructor < T > getConstructor ( Class < ? > ... parameterTypes ) throws NoSuchMethodException , SecurityException { return new MetaAnnotatedConstructor ( target . getConstructor ( parameterTypes ) ) ; } public MetaAnnotatedClass < ? > [ ] getDeclaredClasses ( ) throws SecurityException { return to ( target . getDeclaredClasses ( ) ) ; } public MetaAnnotatedField [ ] getDeclaredFields ( ) throws SecurityException { return to ( target . getDeclaredFields ( ) ) ; } public MetaAnnotatedMethod [ ] getDeclaredMethods ( ) throws SecurityException { return to ( target . getDeclaredMethods ( ) ) ; } public MetaAnnotatedConstructor < ? > [ ] getDeclaredConstructors ( ) throws SecurityException { return to ( target . getDeclaredConstructors ( ) ) ; } public MetaAnnotatedField getDeclaredField ( String name ) throws NoSuchFieldException , SecurityException { return to ( target . getDeclaredField ( name ) ) ; } public MetaAnnotatedMethod getDeclaredMethod ( String name , Class < ? > ... parameterTypes ) throws NoSuchMethodException , SecurityException { return to ( target . getDeclaredMethod ( name , parameterTypes ) ) ; } public MetaAnnotatedConstructor < T > getDeclaredConstructor ( Class < ? > ... parameterTypes ) throws NoSuchMethodException , SecurityException { return new MetaAnnotatedConstructor ( target . getDeclaredConstructor ( parameterTypes ) ) ; } public InputStream getResourceAsStream ( String name ) { return target . getResourceAsStream ( name ) ; } public URL getResource ( String name ) { return target . getResource ( name ) ; } public ProtectionDomain getProtectionDomain ( ) { return target . getProtectionDomain ( ) ; } public boolean desiredAssertionStatus ( ) { return target . desiredAssertionStatus ( ) ; } public boolean isEnum ( ) { return target . isEnum ( ) ; } public T [ ] getEnumConstants ( ) { return target . getEnumConstants ( ) ; } public T cast ( Object obj ) { return target . cast ( obj ) ; } public < U > Class < ? extends U > asSubclass ( Class < U > clazz ) { return target . asSubclass ( clazz ) ; } private MetaAnnotatedMethod [ ] to ( Method [ ] a ) { MetaAnnotatedMethod [ ] b = new MetaAnnotatedMethod [ a . length ] ; for ( int i = <NUM_LIT:0> ; i < a . length ; i ++ ) { b [ i ] = new MetaAnnotatedMethod ( a [ i ] ) ; } return b ; } private MetaAnnotatedMethod to ( Method method ) { return new MetaAnnotatedMethod ( method ) ; } private MetaAnnotatedConstructor < ? > [ ] to ( Constructor < ? > [ ] a ) { MetaAnnotatedConstructor < ? > [ ] b = new MetaAnnotatedConstructor [ a . length ] ; for ( int i = <NUM_LIT:0> ; i < a . length ; i ++ ) { b [ i ] = new MetaAnnotatedConstructor ( a [ i ] ) ; } return b ; } private MetaAnnotatedConstructor < ? > to ( Constructor < ? > constructor ) { return new MetaAnnotatedConstructor ( constructor ) ; } private MetaAnnotatedClass < ? > [ ] to ( Class < ? > [ ] a ) { MetaAnnotatedClass < ? > [ ] b = new MetaAnnotatedClass [ a . length ] ; for ( int i = <NUM_LIT:0> ; i < a . length ; i ++ ) { b [ i ] = to ( a [ i ] ) ; } return b ; } private MetaAnnotatedField [ ] to ( Field [ ] a ) { MetaAnnotatedField [ ] b = new MetaAnnotatedField [ a . length ] ; for ( int i = <NUM_LIT:0> ; i < a . length ; i ++ ) { b [ i ] = new MetaAnnotatedField ( a [ i ] ) ; } return b ; } private MetaAnnotatedField to ( Field field ) { return new MetaAnnotatedField ( field ) ; } } </s> |
<s> package org . metatype ; import java . util . Collection ; public interface MetaAnnotated < T > extends Annotated < T > { public Collection < MetaAnnotation < ? > > getMetaAnnotations ( ) ; } </s> |
<s> package org . metatype ; import java . lang . annotation . Annotation ; import java . lang . reflect . Type ; public interface AnnotatedMethod < T > extends AnnotatedMember < T > { public Annotation [ ] [ ] getParameterAnnotations ( ) ; public Class < ? > [ ] getExceptionTypes ( ) ; public Class < ? > [ ] getParameterTypes ( ) ; public String toGenericString ( ) ; public Type [ ] getGenericExceptionTypes ( ) ; public Type [ ] getGenericParameterTypes ( ) ; public boolean isVarArgs ( ) ; } </s> |
<s> package org . metatype ; import java . lang . reflect . AnnotatedElement ; public interface Annotated < T > extends AnnotatedElement { T get ( ) ; } </s> |
<s> package org . metatype ; import javax . annotation . Metaroot ; import javax . annotation . Metatype ; import static java . util . Arrays . asList ; import java . lang . annotation . Annotation ; import java . lang . annotation . Documented ; import java . lang . annotation . ElementType ; import java . lang . annotation . Retention ; import java . lang . annotation . Target ; import java . lang . reflect . AnnotatedElement ; import java . lang . reflect . Constructor ; import java . lang . reflect . Method ; import java . util . ArrayList ; import java . util . Collection ; import java . util . Collections ; import java . util . HashMap ; import java . util . List ; import java . util . Map ; public abstract class MetaAnnotatedObject < T > implements MetaAnnotated < T > { protected final Map < Class < ? extends Annotation > , MetaAnnotation < ? > > annotations = new HashMap < Class < ? extends Annotation > , MetaAnnotation < ? > > ( ) ; protected final T target ; MetaAnnotatedObject ( T target , Map < Class < ? extends Annotation > , MetaAnnotation < ? > > annotations ) { this . target = target ; this . annotations . putAll ( annotations ) ; } public T get ( ) { return target ; } public boolean isAnnotationPresent ( Class < ? extends Annotation > annotationClass ) { return annotations . containsKey ( annotationClass ) ; } public < T extends Annotation > T getAnnotation ( Class < T > annotationClass ) { MetaAnnotation < T > annotation = ( MetaAnnotation < T > ) annotations . get ( annotationClass ) ; return ( annotation == null ) ? null : annotation . get ( ) ; } public Annotation [ ] getAnnotations ( ) { Annotation [ ] annotations = new Annotation [ this . annotations . size ( ) ] ; int i = <NUM_LIT:0> ; for ( MetaAnnotation annotation : this . annotations . values ( ) ) { annotations [ i ++ ] = annotation . get ( ) ; } return annotations ; } public Collection < MetaAnnotation < ? > > getMetaAnnotations ( ) { return Collections . unmodifiableCollection ( annotations . values ( ) ) ; } @ Override public boolean equals ( Object obj ) { return get ( ) . equals ( obj ) ; } @ Override public int hashCode ( ) { return get ( ) . hashCode ( ) ; } @ Override public String toString ( ) { return get ( ) . toString ( ) ; } private static void unroll ( Class < ? extends Annotation > clazz , int depth , Map < Class < ? extends Annotation > , MetaAnnotation < ? > > found ) { if ( ! isMetaAnnotation ( clazz ) ) return ; for ( Annotation annotation : getDeclaredMetaAnnotations ( clazz ) ) { Class < ? extends Annotation > type = annotation . annotationType ( ) ; MetaAnnotation existing = found . get ( type ) ; if ( existing != null ) { if ( existing . getDepth ( ) > depth ) { found . put ( type , new MetaAnnotation ( annotation , depth ) ) ; unroll ( type , depth + <NUM_LIT:1> , found ) ; } else if ( existing . getDepth ( ) < depth ) { } else { existing . getConflicts ( ) . add ( new MetaAnnotation ( annotation , depth ) ) ; } } else { found . put ( type , new MetaAnnotation ( annotation , depth ) ) ; unroll ( type , depth + <NUM_LIT:1> , found ) ; } } } private static Collection < Annotation > getDeclaredMetaAnnotations ( Class < ? extends Annotation > clazz ) { Map < Class , Annotation > map = new HashMap < Class , Annotation > ( ) ; for ( Annotation annotation : clazz . getDeclaredAnnotations ( ) ) { map . put ( annotation . annotationType ( ) , annotation ) ; } List < Annotation [ ] > groups = new ArrayList < Annotation [ ] > ( ) ; Class < ? extends Annotation > metatype = getMetatype ( clazz ) ; if ( metatype != null ) { try { Class < ? > def = clazz . getClassLoader ( ) . loadClass ( clazz . getName ( ) + "<STR_LIT>" ) ; List < AnnotatedElement > elements = new ArrayList < AnnotatedElement > ( ) ; elements . addAll ( asList ( def . getDeclaredFields ( ) ) ) ; elements . addAll ( asList ( def . getDeclaredConstructors ( ) ) ) ; elements . addAll ( asList ( def . getDeclaredMethods ( ) ) ) ; for ( Method method : def . getDeclaredMethods ( ) ) { for ( Annotation [ ] array : method . getParameterAnnotations ( ) ) { groups . add ( array ) ; } } for ( Constructor constructor : def . getDeclaredConstructors ( ) ) { for ( Annotation [ ] array : constructor . getParameterAnnotations ( ) ) { groups . add ( array ) ; } } for ( AnnotatedElement element : elements ) { groups . add ( element . getDeclaredAnnotations ( ) ) ; } for ( Annotation [ ] annotations : groups ) { if ( contains ( annotations , clazz ) ) { for ( Annotation annotation : annotations ) { map . put ( annotation . annotationType ( ) , annotation ) ; } } } } catch ( ClassNotFoundException e ) { } } map . remove ( Target . class ) ; map . remove ( Retention . class ) ; map . remove ( Documented . class ) ; if ( ! isMetaAnnotation ( metatype ) ) map . remove ( metatype ) ; map . remove ( clazz ) ; return map . values ( ) ; } private static boolean contains ( Annotation [ ] annotations , Class < ? extends Annotation > clazz ) { for ( Annotation annotation : annotations ) { if ( clazz . equals ( annotation . annotationType ( ) ) ) return true ; } return false ; } private static Class < ? extends Annotation > getMetatype ( Class < ? extends Annotation > clazz ) { for ( Annotation annotation : clazz . getDeclaredAnnotations ( ) ) { Class < ? extends Annotation > type = annotation . annotationType ( ) ; if ( isMetatypeAnnotation ( type ) ) return type ; } return null ; } private static boolean isMetaAnnotation ( Class < ? extends Annotation > clazz ) { for ( Annotation annotation : clazz . getDeclaredAnnotations ( ) ) { if ( isMetatypeAnnotation ( annotation . annotationType ( ) ) ) return true ; } return false ; } private static boolean isMetatypeAnnotation ( Class < ? extends Annotation > type ) { if ( Metatype . class . equals ( type ) ) return true ; for ( Annotation annotation : type . getAnnotations ( ) ) { if ( Metaroot . class . equals ( annotation . annotationType ( ) ) ) return true ; } return false ; } private static boolean validTarget ( Class < ? extends Annotation > type ) { final Target target = type . getAnnotation ( Target . class ) ; if ( target == null ) return false ; final ElementType [ ] targets = target . value ( ) ; return targets . length == <NUM_LIT:1> && targets [ <NUM_LIT:0> ] == ElementType . ANNOTATION_TYPE ; } protected static Map < Class < ? extends Annotation > , MetaAnnotation < ? > > unroll ( AnnotatedElement element ) { return unroll ( element . getDeclaredAnnotations ( ) ) ; } protected static Map < Class < ? extends Annotation > , MetaAnnotation < ? > > unroll ( Annotation [ ] annotations ) { final Map < Class < ? extends Annotation > , MetaAnnotation < ? > > map = new HashMap < Class < ? extends Annotation > , MetaAnnotation < ? > > ( ) ; for ( Annotation annotation : annotations ) { map . put ( annotation . annotationType ( ) , new MetaAnnotation ( annotation , <NUM_LIT:0> ) ) ; unroll ( annotation . annotationType ( ) , <NUM_LIT:1> , map ) ; } return map ; } protected Annotation [ ] [ ] unrollParameters ( Annotation [ ] [ ] parameterAnnotations ) { final Annotation [ ] [ ] unrolledParameters = new Annotation [ parameterAnnotations . length ] [ ] ; int i = <NUM_LIT:0> ; for ( Annotation [ ] annotations : parameterAnnotations ) { final Map < Class < ? extends Annotation > , MetaAnnotation < ? > > map = unroll ( annotations ) ; int j = <NUM_LIT:0> ; final Annotation [ ] unrolled = new Annotation [ map . size ( ) ] ; for ( MetaAnnotation < ? > metaAnnotation : map . values ( ) ) { unrolled [ j ++ ] = metaAnnotation . get ( ) ; } unrolledParameters [ i ++ ] = unrolled ; } return unrolledParameters ; } } </s> |
<s> package org . metatype ; import static java . lang . annotation . ElementType . ANNOTATION_TYPE ; import static java . lang . annotation . ElementType . PARAMETER ; import static java . lang . annotation . RetentionPolicy . RUNTIME ; import java . lang . annotation . Annotation ; import java . lang . annotation . Retention ; import java . lang . annotation . RetentionPolicy ; import java . lang . annotation . Target ; import java . lang . reflect . Method ; import java . util . HashMap ; import java . util . Map ; import junit . framework . TestCase ; import javax . annotation . Metatype ; public class MetaAnnotatedMethodParametersTest extends TestCase { public void test ( ) throws Exception { final Class < ? > [ ] classes = new Class [ ] { Square . class , Circle . class , Triangle . class , Oval . class , Store . class , Farm . class , None . class } ; final Map < String , Annotated < Method > > map = new HashMap < String , Annotated < Method > > ( ) ; for ( Class < ? > clazz : classes ) { final MetaAnnotatedClass < ? > annotatedClass = new MetaAnnotatedClass ( clazz ) ; for ( MetaAnnotatedMethod method : annotatedClass . getMethods ( ) ) { map . put ( method . getName ( ) , method ) ; } } { Annotation [ ] annotations = getAnnotations ( map , "<STR_LIT>" ) ; assertTrue ( contains ( Color . class , annotations ) ) ; assertTrue ( contains ( Red . class , annotations ) ) ; assertEquals ( "<STR_LIT>" , get ( Color . class , annotations ) . value ( ) ) ; assertEquals ( <NUM_LIT:2> , annotations . length ) ; } { Annotation [ ] annotations = getAnnotations ( map , "<STR_LIT>" ) ; assertTrue ( contains ( Color . class , annotations ) ) ; assertTrue ( contains ( Red . class , annotations ) ) ; assertEquals ( "<STR_LIT>" , get ( Color . class , annotations ) . value ( ) ) ; assertEquals ( <NUM_LIT:2> , annotations . length ) ; } { Annotation [ ] annotations = getAnnotations ( map , "<STR_LIT>" ) ; assertTrue ( contains ( Color . class , annotations ) ) ; assertTrue ( contains ( Red . class , annotations ) ) ; assertTrue ( contains ( Crimson . class , annotations ) ) ; assertEquals ( "<STR_LIT>" , get ( Color . class , annotations ) . value ( ) ) ; assertEquals ( <NUM_LIT:3> , annotations . length ) ; } { Annotation [ ] annotations = getAnnotations ( map , "<STR_LIT>" ) ; assertTrue ( contains ( Color . class , annotations ) ) ; assertTrue ( contains ( Egg . class , annotations ) ) ; assertTrue ( contains ( Chicken . class , annotations ) ) ; assertEquals ( "<STR_LIT>" , get ( Color . class , annotations ) . value ( ) ) ; assertEquals ( <NUM_LIT:3> , annotations . length ) ; } { Annotation [ ] annotations = getAnnotations ( map , "<STR_LIT>" ) ; assertTrue ( contains ( Color . class , annotations ) ) ; assertTrue ( contains ( Egg . class , annotations ) ) ; assertTrue ( contains ( Chicken . class , annotations ) ) ; assertEquals ( "<STR_LIT>" , get ( Color . class , annotations ) . value ( ) ) ; assertEquals ( <NUM_LIT:3> , annotations . length ) ; } } private Annotation [ ] getAnnotations ( Map < String , Annotated < Method > > map , String key ) { final MetaAnnotatedMethod method = ( MetaAnnotatedMethod ) map . get ( key ) ; assertNotNull ( method ) ; return method . getParameterAnnotations ( ) [ <NUM_LIT:0> ] ; } public < T extends Annotation > T get ( Class < T > type , Annotation [ ] annotations ) { for ( Annotation annotation : annotations ) { if ( annotation . annotationType ( ) == type ) return ( T ) annotation ; } return null ; } private boolean contains ( Class < ? extends Annotation > type , Annotation [ ] annotations ) { return get ( type , annotations ) != null ; } @ Target ( { PARAMETER } ) @ Retention ( RUNTIME ) public static @ interface Color { String value ( ) default "<STR_LIT>" ; } @ Metatype @ Target ( { PARAMETER } ) @ Retention ( RUNTIME ) public static @ interface Red { public interface $ { public void method ( @ Red @ Color ( "<STR_LIT>" ) Object object ) ; } } @ Metatype @ Target ( { PARAMETER } ) @ Retention ( RUNTIME ) public static @ interface Crimson { public interface $ { public void method ( @ Crimson @ Red Object object ) ; } } @ Metatype @ Target ( { PARAMETER } ) @ Retention ( RUNTIME ) public static @ interface Green { public interface $ { public void method ( @ Green @ Color ( "<STR_LIT>" ) Object object ) ; } } @ Metatype @ Target ( { PARAMETER } ) @ Retention ( RUNTIME ) public static @ interface DarkGreen { public interface $ { public void method ( @ DarkGreen @ Green Object object ) ; } } @ Metatype @ Target ( { PARAMETER } ) @ Retention ( RUNTIME ) public static @ interface Forrest { public interface $ { public void method ( @ Forrest @ DarkGreen Object object ) ; } } @ Metatype @ Target ( { PARAMETER } ) @ Retention ( RUNTIME ) public static @ interface Chicken { public interface $ { public void method ( @ Chicken @ Color ( "<STR_LIT>" ) @ Egg Object object ) ; } } @ Metatype @ Target ( { PARAMETER } ) @ Retention ( RUNTIME ) public static @ interface Egg { public interface $ { public void method ( @ Egg @ Color ( "<STR_LIT>" ) @ Chicken Object object ) ; } } public static class Square { public void square ( @ Red Object object ) { } } public static class Circle { public void circle ( @ Red @ Color ( "<STR_LIT>" ) Object object ) { } } public static class Triangle { public void triangle ( @ Crimson Object object ) { } } public static class Oval { public void oval ( @ Forrest Object object ) { } } public static class None { public void none ( Object object ) { } } public static class Store { public void store ( @ Egg Object object ) { } } public static class Farm { public void farm ( @ Chicken Object object ) { } } } </s> |
<s> package org . metatype ; import static java . lang . annotation . ElementType . ANNOTATION_TYPE ; import static java . lang . annotation . ElementType . CONSTRUCTOR ; import static java . lang . annotation . RetentionPolicy . RUNTIME ; import java . lang . annotation . Annotation ; import java . lang . annotation . Retention ; import java . lang . annotation . RetentionPolicy ; import java . lang . annotation . Target ; import java . lang . reflect . Constructor ; import java . util . HashMap ; import java . util . List ; import java . util . Map ; import junit . framework . TestCase ; import javax . annotation . Metatype ; public class MetaAnnotatedConstructorTest extends TestCase { public void test ( ) throws Exception { final Class < ? > [ ] classes = new Class [ ] { Square . class , Circle . class , Triangle . class , Oval . class , Store . class , Farm . class , None . class } ; final Map < String , Annotated < Constructor > > map = new HashMap < String , Annotated < Constructor > > ( ) ; for ( Class < ? > clazz : classes ) { final MetaAnnotatedClass < ? > annotatedClass = new MetaAnnotatedClass ( clazz ) ; for ( MetaAnnotatedConstructor constructor : annotatedClass . getConstructors ( ) ) { map . put ( annotatedClass . getSimpleName ( ) . toLowerCase ( ) , constructor ) ; } } { final java . lang . reflect . AnnotatedElement element = map . get ( "<STR_LIT>" ) ; assertNotNull ( element ) ; assertTrue ( element . isAnnotationPresent ( Color . class ) ) ; assertTrue ( element . getAnnotation ( Color . class ) != null ) ; assertTrue ( contains ( Color . class , element . getDeclaredAnnotations ( ) ) ) ; assertTrue ( contains ( Color . class , element . getAnnotations ( ) ) ) ; assertEquals ( "<STR_LIT>" , element . getAnnotation ( Color . class ) . value ( ) ) ; assertTrue ( element . isAnnotationPresent ( Red . class ) ) ; assertTrue ( element . getAnnotation ( Red . class ) != null ) ; assertTrue ( contains ( Red . class , element . getDeclaredAnnotations ( ) ) ) ; assertTrue ( contains ( Red . class , element . getAnnotations ( ) ) ) ; assertEquals ( <NUM_LIT:2> , element . getDeclaredAnnotations ( ) . length ) ; assertEquals ( <NUM_LIT:2> , element . getAnnotations ( ) . length ) ; } { final java . lang . reflect . AnnotatedElement target = map . get ( "<STR_LIT>" ) ; assertNotNull ( target ) ; assertTrue ( target . isAnnotationPresent ( Color . class ) ) ; assertTrue ( target . getAnnotation ( Color . class ) != null ) ; assertTrue ( ! contains ( Color . class , target . getDeclaredAnnotations ( ) ) ) ; assertTrue ( contains ( Color . class , target . getAnnotations ( ) ) ) ; assertEquals ( "<STR_LIT>" , target . getAnnotation ( Color . class ) . value ( ) ) ; assertTrue ( target . isAnnotationPresent ( Red . class ) ) ; assertTrue ( target . getAnnotation ( Red . class ) != null ) ; assertTrue ( contains ( Red . class , target . getDeclaredAnnotations ( ) ) ) ; assertTrue ( contains ( Red . class , target . getAnnotations ( ) ) ) ; assertEquals ( <NUM_LIT:1> , target . getDeclaredAnnotations ( ) . length ) ; assertEquals ( <NUM_LIT:2> , target . getAnnotations ( ) . length ) ; } { final java . lang . reflect . AnnotatedElement annotated = map . get ( "<STR_LIT>" ) ; assertNotNull ( annotated ) ; assertTrue ( annotated . isAnnotationPresent ( Color . class ) ) ; assertTrue ( annotated . getAnnotation ( Color . class ) != null ) ; assertTrue ( ! contains ( Color . class , annotated . getDeclaredAnnotations ( ) ) ) ; assertTrue ( contains ( Color . class , annotated . getAnnotations ( ) ) ) ; assertEquals ( "<STR_LIT>" , annotated . getAnnotation ( Color . class ) . value ( ) ) ; assertTrue ( annotated . isAnnotationPresent ( Red . class ) ) ; assertTrue ( annotated . getAnnotation ( Red . class ) != null ) ; assertTrue ( ! contains ( Red . class , annotated . getDeclaredAnnotations ( ) ) ) ; assertTrue ( contains ( Red . class , annotated . getAnnotations ( ) ) ) ; assertTrue ( annotated . isAnnotationPresent ( Crimson . class ) ) ; assertTrue ( annotated . getAnnotation ( Crimson . class ) != null ) ; assertTrue ( contains ( Crimson . class , annotated . getDeclaredAnnotations ( ) ) ) ; assertTrue ( contains ( Crimson . class , annotated . getAnnotations ( ) ) ) ; assertEquals ( <NUM_LIT:1> , annotated . getDeclaredAnnotations ( ) . length ) ; assertEquals ( <NUM_LIT:3> , annotated . getAnnotations ( ) . length ) ; } { final java . lang . reflect . AnnotatedElement annotated = map . get ( "<STR_LIT>" ) ; assertNotNull ( annotated ) ; assertTrue ( annotated . isAnnotationPresent ( Color . class ) ) ; assertTrue ( annotated . getAnnotation ( Color . class ) != null ) ; assertTrue ( ! contains ( Color . class , annotated . getDeclaredAnnotations ( ) ) ) ; assertTrue ( contains ( Color . class , annotated . getAnnotations ( ) ) ) ; assertEquals ( "<STR_LIT>" , annotated . getAnnotation ( Color . class ) . value ( ) ) ; assertTrue ( annotated . isAnnotationPresent ( Egg . class ) ) ; assertTrue ( annotated . getAnnotation ( Egg . class ) != null ) ; assertTrue ( contains ( Egg . class , annotated . getDeclaredAnnotations ( ) ) ) ; assertTrue ( contains ( Egg . class , annotated . getAnnotations ( ) ) ) ; assertTrue ( annotated . isAnnotationPresent ( Chicken . class ) ) ; assertTrue ( annotated . getAnnotation ( Chicken . class ) != null ) ; assertTrue ( ! contains ( Chicken . class , annotated . getDeclaredAnnotations ( ) ) ) ; assertTrue ( contains ( Chicken . class , annotated . getAnnotations ( ) ) ) ; assertEquals ( <NUM_LIT:1> , annotated . getDeclaredAnnotations ( ) . length ) ; assertEquals ( <NUM_LIT:3> , annotated . getAnnotations ( ) . length ) ; } { final java . lang . reflect . AnnotatedElement annotated = map . get ( "<STR_LIT>" ) ; assertNotNull ( annotated ) ; assertTrue ( annotated . isAnnotationPresent ( Color . class ) ) ; assertTrue ( annotated . getAnnotation ( Color . class ) != null ) ; assertTrue ( ! contains ( Color . class , annotated . getDeclaredAnnotations ( ) ) ) ; assertTrue ( contains ( Color . class , annotated . getAnnotations ( ) ) ) ; assertEquals ( "<STR_LIT>" , annotated . getAnnotation ( Color . class ) . value ( ) ) ; assertTrue ( annotated . isAnnotationPresent ( Egg . class ) ) ; assertTrue ( annotated . getAnnotation ( Egg . class ) != null ) ; assertTrue ( ! contains ( Egg . class , annotated . getDeclaredAnnotations ( ) ) ) ; assertTrue ( contains ( Egg . class , annotated . getAnnotations ( ) ) ) ; assertTrue ( annotated . isAnnotationPresent ( Chicken . class ) ) ; assertTrue ( annotated . getAnnotation ( Chicken . class ) != null ) ; assertTrue ( contains ( Chicken . class , annotated . getDeclaredAnnotations ( ) ) ) ; assertTrue ( contains ( Chicken . class , annotated . getAnnotations ( ) ) ) ; assertEquals ( <NUM_LIT:1> , annotated . getDeclaredAnnotations ( ) . length ) ; assertEquals ( <NUM_LIT:3> , annotated . getAnnotations ( ) . length ) ; } } private boolean contains ( Class < ? extends Annotation > type , Annotation [ ] annotations ) { for ( Annotation annotation : annotations ) { if ( type . isAssignableFrom ( annotation . annotationType ( ) ) ) return true ; } return false ; } @ Target ( { CONSTRUCTOR } ) @ Retention ( RUNTIME ) public static @ interface Color { String value ( ) default "<STR_LIT>" ; } @ Metatype @ Target ( { CONSTRUCTOR } ) @ Retention ( RUNTIME ) public static @ interface Red { public class $ { @ Red @ Color ( "<STR_LIT>" ) public $ ( ) { } } } @ Metatype @ Target ( { CONSTRUCTOR } ) @ Retention ( RUNTIME ) public static @ interface Crimson { public class $ { @ Crimson @ Red public $ ( ) { } } } @ Metatype @ Target ( { CONSTRUCTOR } ) @ Retention ( RUNTIME ) public static @ interface Green { public class $ { @ Green @ Color ( "<STR_LIT>" ) public $ ( ) { } } } @ Metatype @ Target ( { CONSTRUCTOR } ) @ Retention ( RUNTIME ) public static @ interface DarkGreen { public class $ { @ DarkGreen @ Green public $ ( ) { } } } @ Metatype @ Target ( { CONSTRUCTOR } ) @ Retention ( RUNTIME ) public static @ interface Forrest { public class $ { @ Forrest @ DarkGreen public $ ( ) { } } } @ Metatype @ Target ( { CONSTRUCTOR } ) @ Retention ( RUNTIME ) public static @ interface Chicken { public class $ { @ Chicken @ Color ( "<STR_LIT>" ) @ Egg public $ ( ) { } } } @ Metatype @ Target ( { CONSTRUCTOR } ) @ Retention ( RUNTIME ) public static @ interface Egg { public class $ { @ Egg @ Color ( "<STR_LIT>" ) @ Chicken public $ ( ) { } } } public static class Square { @ Red public Square ( String s , int i ) { } } public static class Circle { @ Red @ Color ( "<STR_LIT>" ) public Circle ( int i ) { } } public static class Triangle { @ Crimson public Triangle ( boolean ... b ) { } } public static class Oval { @ Forrest public Oval ( boolean ... b ) { } } public static class None { public None ( List < String > l ) { } } public static class Store { @ Egg public Store ( ) { } } public static class Farm { @ Chicken public Farm ( ) { } } } </s> |
<s> package org . metatype ; import static java . lang . annotation . ElementType . ANNOTATION_TYPE ; import static java . lang . annotation . ElementType . PARAMETER ; import static java . lang . annotation . RetentionPolicy . RUNTIME ; import java . lang . annotation . Annotation ; import java . lang . annotation . Retention ; import java . lang . annotation . RetentionPolicy ; import java . lang . annotation . Target ; import java . lang . reflect . Constructor ; import java . util . HashMap ; import java . util . Map ; import junit . framework . TestCase ; import javax . annotation . Metatype ; public class MetaAnnotatedConstructorParametersTest extends TestCase { public void test ( ) throws Exception { final Class < ? > [ ] classes = new Class [ ] { Square . class , Circle . class , Triangle . class , Oval . class , Store . class , Farm . class , None . class } ; final Map < String , Annotated < Constructor > > map = new HashMap < String , Annotated < Constructor > > ( ) ; for ( Class < ? > clazz : classes ) { final MetaAnnotatedClass < ? > annotatedClass = new MetaAnnotatedClass ( clazz ) ; for ( MetaAnnotatedConstructor method : annotatedClass . getConstructors ( ) ) { map . put ( annotatedClass . getSimpleName ( ) . toLowerCase ( ) , method ) ; } } { Annotation [ ] annotations = getAnnotations ( map , "<STR_LIT>" ) ; assertTrue ( contains ( Color . class , annotations ) ) ; assertTrue ( contains ( Red . class , annotations ) ) ; assertEquals ( "<STR_LIT>" , get ( Color . class , annotations ) . value ( ) ) ; assertEquals ( <NUM_LIT:2> , annotations . length ) ; } { Annotation [ ] annotations = getAnnotations ( map , "<STR_LIT>" ) ; assertTrue ( contains ( Color . class , annotations ) ) ; assertTrue ( contains ( Red . class , annotations ) ) ; assertEquals ( "<STR_LIT>" , get ( Color . class , annotations ) . value ( ) ) ; assertEquals ( <NUM_LIT:2> , annotations . length ) ; } { Annotation [ ] annotations = getAnnotations ( map , "<STR_LIT>" ) ; assertTrue ( contains ( Color . class , annotations ) ) ; assertTrue ( contains ( Red . class , annotations ) ) ; assertTrue ( contains ( Crimson . class , annotations ) ) ; assertEquals ( "<STR_LIT>" , get ( Color . class , annotations ) . value ( ) ) ; assertEquals ( <NUM_LIT:3> , annotations . length ) ; } { Annotation [ ] annotations = getAnnotations ( map , "<STR_LIT>" ) ; assertTrue ( contains ( Color . class , annotations ) ) ; assertTrue ( contains ( Egg . class , annotations ) ) ; assertTrue ( contains ( Chicken . class , annotations ) ) ; assertEquals ( "<STR_LIT>" , get ( Color . class , annotations ) . value ( ) ) ; assertEquals ( <NUM_LIT:3> , annotations . length ) ; } { Annotation [ ] annotations = getAnnotations ( map , "<STR_LIT>" ) ; assertTrue ( contains ( Color . class , annotations ) ) ; assertTrue ( contains ( Egg . class , annotations ) ) ; assertTrue ( contains ( Chicken . class , annotations ) ) ; assertEquals ( "<STR_LIT>" , get ( Color . class , annotations ) . value ( ) ) ; assertEquals ( <NUM_LIT:3> , annotations . length ) ; } } private Annotation [ ] getAnnotations ( Map < String , Annotated < Constructor > > map , String key ) { final MetaAnnotatedConstructor constructor = ( MetaAnnotatedConstructor ) map . get ( key ) ; assertNotNull ( constructor ) ; return constructor . getParameterAnnotations ( ) [ <NUM_LIT:0> ] ; } public < T extends Annotation > T get ( Class < T > type , Annotation [ ] annotations ) { for ( Annotation annotation : annotations ) { if ( annotation . annotationType ( ) == type ) return ( T ) annotation ; } return null ; } private boolean contains ( Class < ? extends Annotation > type , Annotation [ ] annotations ) { return get ( type , annotations ) != null ; } @ Target ( { PARAMETER } ) @ Retention ( RUNTIME ) public static @ interface Color { String value ( ) default "<STR_LIT>" ; } @ Metatype @ Target ( { PARAMETER } ) @ Retention ( RUNTIME ) public static @ interface Red { public interface $ { public void method ( @ Red @ Color ( "<STR_LIT>" ) Object object ) ; } } @ Metatype @ Target ( { PARAMETER } ) @ Retention ( RUNTIME ) public static @ interface Crimson { public interface $ { public void method ( @ Crimson @ Red Object object ) ; } } @ Metatype @ Target ( { PARAMETER } ) @ Retention ( RUNTIME ) public static @ interface Green { public interface $ { public void method ( @ Green @ Color ( "<STR_LIT>" ) Object object ) ; } } @ Metatype @ Target ( { PARAMETER } ) @ Retention ( RUNTIME ) public static @ interface DarkGreen { public interface $ { public void method ( @ DarkGreen @ Green Object object ) ; } } @ Metatype @ Target ( { PARAMETER } ) @ Retention ( RUNTIME ) public static @ interface Forrest { public interface $ { public void method ( @ Forrest @ DarkGreen Object object ) ; } } @ Metatype @ Target ( { PARAMETER } ) @ Retention ( RUNTIME ) public static @ interface Chicken { public interface $ { public void method ( @ Chicken @ Color ( "<STR_LIT>" ) @ Egg Object object ) ; } } @ Metatype @ Target ( { PARAMETER } ) @ Retention ( RUNTIME ) public static @ interface Egg { public interface $ { public void method ( @ Egg @ Color ( "<STR_LIT>" ) @ Chicken Object object ) ; } } public static class Square { public Square ( @ Red Object object ) { } } public static class Circle { public Circle ( @ Red @ Color ( "<STR_LIT>" ) Object object ) { } } public static class Triangle { public Triangle ( @ Crimson Object object ) { } } public static class Oval { public Oval ( @ Forrest Object object ) { } } public static class None { public None ( Object object ) { } } public static class Store { public Store ( @ Egg Object object ) { } } public static class Farm { public Farm ( @ Chicken Object object ) { } } } </s> |
<s> package org . metatype ; import static java . lang . annotation . ElementType . ANNOTATION_TYPE ; import static java . lang . annotation . ElementType . METHOD ; import static java . lang . annotation . RetentionPolicy . RUNTIME ; import java . lang . annotation . Annotation ; import java . lang . annotation . Retention ; import java . lang . annotation . RetentionPolicy ; import java . lang . annotation . Target ; import java . lang . reflect . Method ; import java . util . HashMap ; import java . util . List ; import java . util . Map ; import junit . framework . TestCase ; import javax . annotation . Metatype ; public class MetaAnnotatedMethodTest extends TestCase { public void test ( ) throws Exception { final Class < ? > [ ] classes = new Class [ ] { Square . class , Circle . class , Triangle . class , Oval . class , Store . class , Farm . class , None . class } ; final Map < String , Annotated < Method > > map = new HashMap < String , Annotated < Method > > ( ) ; for ( Class < ? > clazz : classes ) { final MetaAnnotatedClass < ? > annotatedClass = new MetaAnnotatedClass ( clazz ) ; for ( MetaAnnotatedMethod method : annotatedClass . getMethods ( ) ) { map . put ( method . getName ( ) , method ) ; } } { final java . lang . reflect . AnnotatedElement element = map . get ( "<STR_LIT>" ) ; assertNotNull ( element ) ; assertTrue ( element . isAnnotationPresent ( Color . class ) ) ; assertTrue ( element . getAnnotation ( Color . class ) != null ) ; assertTrue ( contains ( Color . class , element . getDeclaredAnnotations ( ) ) ) ; assertTrue ( contains ( Color . class , element . getAnnotations ( ) ) ) ; assertEquals ( "<STR_LIT>" , element . getAnnotation ( Color . class ) . value ( ) ) ; assertTrue ( element . isAnnotationPresent ( Red . class ) ) ; assertTrue ( element . getAnnotation ( Red . class ) != null ) ; assertTrue ( contains ( Red . class , element . getDeclaredAnnotations ( ) ) ) ; assertTrue ( contains ( Red . class , element . getAnnotations ( ) ) ) ; assertEquals ( <NUM_LIT:2> , element . getDeclaredAnnotations ( ) . length ) ; assertEquals ( <NUM_LIT:2> , element . getAnnotations ( ) . length ) ; } { final java . lang . reflect . AnnotatedElement target = map . get ( "<STR_LIT>" ) ; assertNotNull ( target ) ; assertTrue ( target . isAnnotationPresent ( Color . class ) ) ; assertTrue ( target . getAnnotation ( Color . class ) != null ) ; assertTrue ( ! contains ( Color . class , target . getDeclaredAnnotations ( ) ) ) ; assertTrue ( contains ( Color . class , target . getAnnotations ( ) ) ) ; assertEquals ( "<STR_LIT>" , target . getAnnotation ( Color . class ) . value ( ) ) ; assertTrue ( target . isAnnotationPresent ( Red . class ) ) ; assertTrue ( target . getAnnotation ( Red . class ) != null ) ; assertTrue ( contains ( Red . class , target . getDeclaredAnnotations ( ) ) ) ; assertTrue ( contains ( Red . class , target . getAnnotations ( ) ) ) ; assertEquals ( <NUM_LIT:1> , target . getDeclaredAnnotations ( ) . length ) ; assertEquals ( <NUM_LIT:2> , target . getAnnotations ( ) . length ) ; } { final java . lang . reflect . AnnotatedElement annotated = map . get ( "<STR_LIT>" ) ; assertNotNull ( annotated ) ; assertTrue ( annotated . isAnnotationPresent ( Color . class ) ) ; assertTrue ( annotated . getAnnotation ( Color . class ) != null ) ; assertTrue ( ! contains ( Color . class , annotated . getDeclaredAnnotations ( ) ) ) ; assertTrue ( contains ( Color . class , annotated . getAnnotations ( ) ) ) ; assertEquals ( "<STR_LIT>" , annotated . getAnnotation ( Color . class ) . value ( ) ) ; assertTrue ( annotated . isAnnotationPresent ( Red . class ) ) ; assertTrue ( annotated . getAnnotation ( Red . class ) != null ) ; assertTrue ( ! contains ( Red . class , annotated . getDeclaredAnnotations ( ) ) ) ; assertTrue ( contains ( Red . class , annotated . getAnnotations ( ) ) ) ; assertTrue ( annotated . isAnnotationPresent ( Crimson . class ) ) ; assertTrue ( annotated . getAnnotation ( Crimson . class ) != null ) ; assertTrue ( contains ( Crimson . class , annotated . getDeclaredAnnotations ( ) ) ) ; assertTrue ( contains ( Crimson . class , annotated . getAnnotations ( ) ) ) ; assertEquals ( <NUM_LIT:1> , annotated . getDeclaredAnnotations ( ) . length ) ; assertEquals ( <NUM_LIT:3> , annotated . getAnnotations ( ) . length ) ; } { final java . lang . reflect . AnnotatedElement annotated = map . get ( "<STR_LIT>" ) ; assertNotNull ( annotated ) ; assertTrue ( annotated . isAnnotationPresent ( Color . class ) ) ; assertTrue ( annotated . getAnnotation ( Color . class ) != null ) ; assertTrue ( ! contains ( Color . class , annotated . getDeclaredAnnotations ( ) ) ) ; assertTrue ( contains ( Color . class , annotated . getAnnotations ( ) ) ) ; assertEquals ( "<STR_LIT>" , annotated . getAnnotation ( Color . class ) . value ( ) ) ; assertTrue ( annotated . isAnnotationPresent ( Egg . class ) ) ; assertTrue ( annotated . getAnnotation ( Egg . class ) != null ) ; assertTrue ( contains ( Egg . class , annotated . getDeclaredAnnotations ( ) ) ) ; assertTrue ( contains ( Egg . class , annotated . getAnnotations ( ) ) ) ; assertTrue ( annotated . isAnnotationPresent ( Chicken . class ) ) ; assertTrue ( annotated . getAnnotation ( Chicken . class ) != null ) ; assertTrue ( ! contains ( Chicken . class , annotated . getDeclaredAnnotations ( ) ) ) ; assertTrue ( contains ( Chicken . class , annotated . getAnnotations ( ) ) ) ; assertEquals ( <NUM_LIT:1> , annotated . getDeclaredAnnotations ( ) . length ) ; assertEquals ( <NUM_LIT:3> , annotated . getAnnotations ( ) . length ) ; } { final java . lang . reflect . AnnotatedElement annotated = map . get ( "<STR_LIT>" ) ; assertNotNull ( annotated ) ; assertTrue ( annotated . isAnnotationPresent ( Color . class ) ) ; assertTrue ( annotated . getAnnotation ( Color . class ) != null ) ; assertTrue ( ! contains ( Color . class , annotated . getDeclaredAnnotations ( ) ) ) ; assertTrue ( contains ( Color . class , annotated . getAnnotations ( ) ) ) ; assertEquals ( "<STR_LIT>" , annotated . getAnnotation ( Color . class ) . value ( ) ) ; assertTrue ( annotated . isAnnotationPresent ( Egg . class ) ) ; assertTrue ( annotated . getAnnotation ( Egg . class ) != null ) ; assertTrue ( ! contains ( Egg . class , annotated . getDeclaredAnnotations ( ) ) ) ; assertTrue ( contains ( Egg . class , annotated . getAnnotations ( ) ) ) ; assertTrue ( annotated . isAnnotationPresent ( Chicken . class ) ) ; assertTrue ( annotated . getAnnotation ( Chicken . class ) != null ) ; assertTrue ( contains ( Chicken . class , annotated . getDeclaredAnnotations ( ) ) ) ; assertTrue ( contains ( Chicken . class , annotated . getAnnotations ( ) ) ) ; assertEquals ( <NUM_LIT:1> , annotated . getDeclaredAnnotations ( ) . length ) ; assertEquals ( <NUM_LIT:3> , annotated . getAnnotations ( ) . length ) ; } } private boolean contains ( Class < ? extends Annotation > type , Annotation [ ] annotations ) { for ( Annotation annotation : annotations ) { if ( type . isAssignableFrom ( annotation . annotationType ( ) ) ) return true ; } return false ; } @ Target ( { METHOD } ) @ Retention ( RUNTIME ) public static @ interface Color { String value ( ) default "<STR_LIT>" ; } @ Metatype @ Target ( { METHOD } ) @ Retention ( RUNTIME ) public static @ interface Red { public interface $ { @ Red @ Color ( "<STR_LIT>" ) public void method ( ) ; } } @ Metatype @ Target ( { METHOD } ) @ Retention ( RUNTIME ) public static @ interface Crimson { public interface $ { @ Crimson @ Red public void method ( ) ; } } @ Metatype @ Target ( { METHOD } ) @ Retention ( RUNTIME ) public static @ interface Green { public interface $ { @ Green @ Color ( "<STR_LIT>" ) public void method ( ) ; } } @ Metatype @ Target ( { METHOD } ) @ Retention ( RUNTIME ) public static @ interface DarkGreen { public interface $ { @ DarkGreen @ Green public void method ( ) ; } } @ Metatype @ Target ( { METHOD } ) @ Retention ( RUNTIME ) public static @ interface Forrest { public interface $ { @ Forrest @ DarkGreen public void method ( ) ; } } @ Metatype @ Target ( { METHOD } ) @ Retention ( RUNTIME ) public static @ interface Chicken { public interface $ { @ Chicken @ Color ( "<STR_LIT>" ) @ Egg public void method ( ) ; } } @ Metatype @ Target ( { METHOD } ) @ Retention ( RUNTIME ) public static @ interface Egg { public interface $ { @ Egg @ Color ( "<STR_LIT>" ) @ Chicken public void method ( ) ; } } public static class Square { @ Red public void square ( String s , int i ) { } } public static class Circle { @ Red @ Color ( "<STR_LIT>" ) public void circle ( int i ) { } } public static class Triangle { @ Crimson public void triangle ( boolean ... b ) { } } public static class Oval { @ Forrest public void oval ( boolean ... b ) { } } public static class None { public void none ( List < String > l ) { } } public static class Store { @ Egg public void store ( ) { } } public static class Farm { @ Chicken public void farm ( ) { } } } </s> |
<s> package org . metatype ; import static java . lang . annotation . ElementType . ANNOTATION_TYPE ; import static java . lang . annotation . ElementType . TYPE ; import static java . lang . annotation . RetentionPolicy . RUNTIME ; import java . lang . annotation . Annotation ; import java . lang . annotation . Retention ; import java . lang . annotation . RetentionPolicy ; import java . lang . annotation . Target ; import junit . framework . TestCase ; import javax . annotation . Metaroot ; public class MetatypeAvailableTest extends TestCase { private boolean contains ( Class < ? extends Annotation > type , Annotation [ ] annotations ) { for ( Annotation annotation : annotations ) { if ( type . isAssignableFrom ( annotation . annotationType ( ) ) ) return true ; } return false ; } public void testSquare ( ) { final java . lang . reflect . AnnotatedElement annotated = new MetaAnnotatedClass ( Square . class ) ; assertNotNull ( annotated ) ; assertTrue ( annotated . isAnnotationPresent ( Color . class ) ) ; assertTrue ( annotated . getAnnotation ( Color . class ) != null ) ; assertTrue ( ! contains ( Color . class , annotated . getDeclaredAnnotations ( ) ) ) ; assertTrue ( contains ( Color . class , annotated . getAnnotations ( ) ) ) ; assertEquals ( "<STR_LIT>" , annotated . getAnnotation ( Color . class ) . value ( ) ) ; assertTrue ( annotated . isAnnotationPresent ( Red . class ) ) ; assertTrue ( annotated . getAnnotation ( Red . class ) != null ) ; assertTrue ( contains ( Red . class , annotated . getDeclaredAnnotations ( ) ) ) ; assertTrue ( contains ( Red . class , annotated . getAnnotations ( ) ) ) ; assertTrue ( contains ( Metatype . class , annotated . getAnnotations ( ) ) ) ; } @ Metatype @ Metaroot @ Retention ( RetentionPolicy . RUNTIME ) @ Target ( ANNOTATION_TYPE ) public @ interface Metatype { } @ Target ( value = { TYPE } ) @ Retention ( value = RUNTIME ) public static @ interface Color { String value ( ) default "<STR_LIT>" ; } @ Metatype @ Color ( "<STR_LIT>" ) @ Target ( value = { TYPE } ) @ Retention ( value = RUNTIME ) public static @ interface Red { } @ Red public static class Square { } } </s> |
<s> package org . metatype ; import static java . lang . annotation . ElementType . ANNOTATION_TYPE ; import static java . lang . annotation . ElementType . TYPE ; import static java . lang . annotation . RetentionPolicy . RUNTIME ; import java . lang . annotation . Annotation ; import java . lang . annotation . Retention ; import java . lang . annotation . RetentionPolicy ; import java . lang . annotation . Target ; import junit . framework . TestCase ; import javax . annotation . Metatype ; public class MetaAnnotatedClassTest extends TestCase { public void test ( ) throws Exception { { final java . lang . reflect . AnnotatedElement annotated = new MetaAnnotatedClass ( Circle . class ) ; assertNotNull ( annotated ) ; assertTrue ( annotated . isAnnotationPresent ( Color . class ) ) ; assertTrue ( annotated . getAnnotation ( Color . class ) != null ) ; assertTrue ( contains ( Color . class , annotated . getDeclaredAnnotations ( ) ) ) ; assertTrue ( contains ( Color . class , annotated . getAnnotations ( ) ) ) ; assertEquals ( "<STR_LIT>" , annotated . getAnnotation ( Color . class ) . value ( ) ) ; } { final java . lang . reflect . AnnotatedElement annotated = new MetaAnnotatedClass ( Triangle . class ) ; assertNotNull ( annotated ) ; assertTrue ( annotated . isAnnotationPresent ( Color . class ) ) ; assertTrue ( annotated . getAnnotation ( Color . class ) != null ) ; assertTrue ( ! contains ( Color . class , annotated . getDeclaredAnnotations ( ) ) ) ; assertTrue ( contains ( Color . class , annotated . getAnnotations ( ) ) ) ; assertEquals ( "<STR_LIT>" , annotated . getAnnotation ( Color . class ) . value ( ) ) ; assertTrue ( annotated . isAnnotationPresent ( Red . class ) ) ; assertTrue ( annotated . getAnnotation ( Red . class ) != null ) ; assertTrue ( ! contains ( Red . class , annotated . getDeclaredAnnotations ( ) ) ) ; assertTrue ( contains ( Red . class , annotated . getAnnotations ( ) ) ) ; assertTrue ( annotated . isAnnotationPresent ( Crimson . class ) ) ; assertTrue ( annotated . getAnnotation ( Crimson . class ) != null ) ; assertTrue ( contains ( Crimson . class , annotated . getDeclaredAnnotations ( ) ) ) ; assertTrue ( contains ( Crimson . class , annotated . getAnnotations ( ) ) ) ; } { final java . lang . reflect . AnnotatedElement annotated = new MetaAnnotatedClass ( Store . class ) ; assertNotNull ( annotated ) ; assertTrue ( annotated . isAnnotationPresent ( Color . class ) ) ; assertTrue ( annotated . getAnnotation ( Color . class ) != null ) ; assertTrue ( ! contains ( Color . class , annotated . getDeclaredAnnotations ( ) ) ) ; assertTrue ( contains ( Color . class , annotated . getAnnotations ( ) ) ) ; assertEquals ( "<STR_LIT>" , annotated . getAnnotation ( Color . class ) . value ( ) ) ; assertTrue ( annotated . isAnnotationPresent ( Egg . class ) ) ; assertTrue ( annotated . getAnnotation ( Egg . class ) != null ) ; assertTrue ( contains ( Egg . class , annotated . getDeclaredAnnotations ( ) ) ) ; assertTrue ( contains ( Egg . class , annotated . getAnnotations ( ) ) ) ; assertTrue ( annotated . isAnnotationPresent ( Chicken . class ) ) ; assertTrue ( annotated . getAnnotation ( Chicken . class ) != null ) ; assertTrue ( ! contains ( Chicken . class , annotated . getDeclaredAnnotations ( ) ) ) ; assertTrue ( contains ( Chicken . class , annotated . getAnnotations ( ) ) ) ; } { final java . lang . reflect . AnnotatedElement annotated = new MetaAnnotatedClass ( Farm . class ) ; assertNotNull ( annotated ) ; assertTrue ( annotated . isAnnotationPresent ( Color . class ) ) ; assertTrue ( annotated . getAnnotation ( Color . class ) != null ) ; assertTrue ( ! contains ( Color . class , annotated . getDeclaredAnnotations ( ) ) ) ; assertTrue ( contains ( Color . class , annotated . getAnnotations ( ) ) ) ; assertEquals ( "<STR_LIT>" , annotated . getAnnotation ( Color . class ) . value ( ) ) ; assertTrue ( annotated . isAnnotationPresent ( Egg . class ) ) ; assertTrue ( annotated . getAnnotation ( Egg . class ) != null ) ; assertTrue ( ! contains ( Egg . class , annotated . getDeclaredAnnotations ( ) ) ) ; assertTrue ( contains ( Egg . class , annotated . getAnnotations ( ) ) ) ; assertTrue ( annotated . isAnnotationPresent ( Chicken . class ) ) ; assertTrue ( annotated . getAnnotation ( Chicken . class ) != null ) ; assertTrue ( contains ( Chicken . class , annotated . getDeclaredAnnotations ( ) ) ) ; assertTrue ( contains ( Chicken . class , annotated . getAnnotations ( ) ) ) ; } { final java . lang . reflect . AnnotatedElement annotated = new MetaAnnotatedClass ( None . class ) ; assertNotNull ( annotated ) ; assertFalse ( annotated . isAnnotationPresent ( NotMeta . class ) ) ; assertFalse ( annotated . isAnnotationPresent ( Metatype . class ) ) ; assertTrue ( annotated . getAnnotation ( NotMeta . class ) == null ) ; assertTrue ( annotated . getAnnotation ( Metatype . class ) == null ) ; assertEquals ( <NUM_LIT:0> , annotated . getDeclaredAnnotations ( ) . length ) ; assertEquals ( <NUM_LIT:0> , annotated . getAnnotations ( ) . length ) ; } } public void testFake ( ) { final java . lang . reflect . AnnotatedElement annotated = new MetaAnnotatedClass ( Fake . class ) ; assertNotNull ( annotated ) ; assertTrue ( annotated . isAnnotationPresent ( NotMeta . class ) ) ; assertTrue ( annotated . getAnnotation ( NotMeta . class ) != null ) ; assertTrue ( contains ( NotMeta . class , annotated . getDeclaredAnnotations ( ) ) ) ; assertTrue ( contains ( NotMeta . class , annotated . getAnnotations ( ) ) ) ; assertFalse ( annotated . isAnnotationPresent ( Color . class ) ) ; assertTrue ( annotated . getAnnotation ( Color . class ) == null ) ; assertFalse ( contains ( Color . class , annotated . getDeclaredAnnotations ( ) ) ) ; assertFalse ( contains ( Color . class , annotated . getAnnotations ( ) ) ) ; } public void testSquare ( ) { final java . lang . reflect . AnnotatedElement annotated = new MetaAnnotatedClass ( Square . class ) ; assertNotNull ( annotated ) ; assertTrue ( annotated . isAnnotationPresent ( Color . class ) ) ; assertTrue ( annotated . getAnnotation ( Color . class ) != null ) ; assertTrue ( ! contains ( Color . class , annotated . getDeclaredAnnotations ( ) ) ) ; assertTrue ( contains ( Color . class , annotated . getAnnotations ( ) ) ) ; assertEquals ( "<STR_LIT>" , annotated . getAnnotation ( Color . class ) . value ( ) ) ; assertTrue ( annotated . isAnnotationPresent ( Red . class ) ) ; assertTrue ( annotated . getAnnotation ( Red . class ) != null ) ; assertTrue ( contains ( Red . class , annotated . getDeclaredAnnotations ( ) ) ) ; assertTrue ( contains ( Red . class , annotated . getAnnotations ( ) ) ) ; assertFalse ( contains ( Metatype . class , annotated . getAnnotations ( ) ) ) ; } private boolean contains ( Class < ? extends Annotation > type , Annotation [ ] annotations ) { for ( Annotation annotation : annotations ) { if ( type . isAssignableFrom ( annotation . annotationType ( ) ) ) return true ; } return false ; } @ Target ( value = { TYPE } ) @ Retention ( value = RUNTIME ) public static @ interface Color { String value ( ) default "<STR_LIT>" ; } @ Metatype @ Color ( "<STR_LIT>" ) @ Target ( value = { TYPE } ) @ Retention ( value = RUNTIME ) public static @ interface Red { } @ Metatype @ Red @ Target ( value = { TYPE } ) @ Retention ( value = RUNTIME ) public static @ interface Crimson { } @ Red @ Target ( value = { TYPE } ) @ Retention ( value = RUNTIME ) public static @ interface NotMeta { } @ Metatype @ Color ( "<STR_LIT>" ) @ Chicken @ Target ( value = { TYPE } ) @ Retention ( value = RUNTIME ) public static @ interface Egg { } @ Metatype @ Color ( "<STR_LIT>" ) @ Egg @ Target ( value = { TYPE } ) @ Retention ( value = RUNTIME ) public static @ interface Chicken { } @ Red public static class Square { } @ Red @ Color ( "<STR_LIT>" ) public static class Circle { } @ Crimson public static class Triangle { } public static class None { } @ NotMeta public static class Fake { } @ Egg public static class Store { } @ Chicken public static class Farm { } } </s> |
<s> package org . metatype ; import static java . lang . annotation . ElementType . ANNOTATION_TYPE ; import static java . lang . annotation . ElementType . FIELD ; import static java . lang . annotation . RetentionPolicy . RUNTIME ; import java . lang . annotation . Annotation ; import java . lang . annotation . Retention ; import java . lang . annotation . RetentionPolicy ; import java . lang . annotation . Target ; import java . lang . reflect . Field ; import java . util . HashMap ; import java . util . Map ; import junit . framework . TestCase ; import javax . annotation . Metatype ; public class MetaAnnotatedFieldTest extends TestCase { public void test ( ) throws Exception { final Class < ? > [ ] classes = new Class [ ] { Square . class , Circle . class , Triangle . class , Oval . class , Store . class , Farm . class , None . class } ; final Map < String , Annotated < Field > > map = new HashMap < String , Annotated < Field > > ( ) ; for ( Class < ? > clazz : classes ) { final MetaAnnotatedClass < ? > annotatedClass = new MetaAnnotatedClass ( clazz ) ; for ( MetaAnnotatedField field : annotatedClass . getDeclaredFields ( ) ) { map . put ( field . getName ( ) , field ) ; } } { final java . lang . reflect . AnnotatedElement annotated = map . get ( "<STR_LIT>" ) ; assertNotNull ( annotated ) ; assertTrue ( annotated . isAnnotationPresent ( Color . class ) ) ; assertTrue ( annotated . getAnnotation ( Color . class ) != null ) ; assertTrue ( contains ( Color . class , annotated . getDeclaredAnnotations ( ) ) ) ; assertTrue ( contains ( Color . class , annotated . getAnnotations ( ) ) ) ; assertEquals ( "<STR_LIT>" , annotated . getAnnotation ( Color . class ) . value ( ) ) ; assertTrue ( annotated . isAnnotationPresent ( Red . class ) ) ; assertTrue ( annotated . getAnnotation ( Red . class ) != null ) ; assertTrue ( contains ( Red . class , annotated . getDeclaredAnnotations ( ) ) ) ; assertTrue ( contains ( Red . class , annotated . getAnnotations ( ) ) ) ; assertEquals ( <NUM_LIT:2> , annotated . getDeclaredAnnotations ( ) . length ) ; assertEquals ( <NUM_LIT:2> , annotated . getAnnotations ( ) . length ) ; } { final java . lang . reflect . AnnotatedElement annotated = map . get ( "<STR_LIT>" ) ; assertNotNull ( annotated ) ; assertTrue ( annotated . isAnnotationPresent ( Color . class ) ) ; assertTrue ( annotated . getAnnotation ( Color . class ) != null ) ; assertTrue ( ! contains ( Color . class , annotated . getDeclaredAnnotations ( ) ) ) ; assertTrue ( contains ( Color . class , annotated . getAnnotations ( ) ) ) ; assertEquals ( "<STR_LIT>" , annotated . getAnnotation ( Color . class ) . value ( ) ) ; assertTrue ( annotated . isAnnotationPresent ( Red . class ) ) ; assertTrue ( annotated . getAnnotation ( Red . class ) != null ) ; assertTrue ( contains ( Red . class , annotated . getDeclaredAnnotations ( ) ) ) ; assertTrue ( contains ( Red . class , annotated . getAnnotations ( ) ) ) ; assertEquals ( <NUM_LIT:1> , annotated . getDeclaredAnnotations ( ) . length ) ; assertEquals ( <NUM_LIT:2> , annotated . getAnnotations ( ) . length ) ; } { final java . lang . reflect . AnnotatedElement annotated = map . get ( "<STR_LIT>" ) ; assertNotNull ( annotated ) ; assertTrue ( annotated . isAnnotationPresent ( Color . class ) ) ; assertTrue ( annotated . getAnnotation ( Color . class ) != null ) ; assertTrue ( ! contains ( Color . class , annotated . getDeclaredAnnotations ( ) ) ) ; assertTrue ( contains ( Color . class , annotated . getAnnotations ( ) ) ) ; assertEquals ( "<STR_LIT>" , annotated . getAnnotation ( Color . class ) . value ( ) ) ; assertTrue ( annotated . isAnnotationPresent ( Red . class ) ) ; assertTrue ( annotated . getAnnotation ( Red . class ) != null ) ; assertTrue ( ! contains ( Red . class , annotated . getDeclaredAnnotations ( ) ) ) ; assertTrue ( contains ( Red . class , annotated . getAnnotations ( ) ) ) ; assertTrue ( annotated . isAnnotationPresent ( Crimson . class ) ) ; assertTrue ( annotated . getAnnotation ( Crimson . class ) != null ) ; assertTrue ( contains ( Crimson . class , annotated . getDeclaredAnnotations ( ) ) ) ; assertTrue ( contains ( Crimson . class , annotated . getAnnotations ( ) ) ) ; assertEquals ( <NUM_LIT:1> , annotated . getDeclaredAnnotations ( ) . length ) ; assertEquals ( <NUM_LIT:3> , annotated . getAnnotations ( ) . length ) ; } { final java . lang . reflect . AnnotatedElement annotated = map . get ( "<STR_LIT>" ) ; assertNotNull ( annotated ) ; assertTrue ( annotated . isAnnotationPresent ( Color . class ) ) ; assertTrue ( annotated . getAnnotation ( Color . class ) != null ) ; assertTrue ( ! contains ( Color . class , annotated . getDeclaredAnnotations ( ) ) ) ; assertTrue ( contains ( Color . class , annotated . getAnnotations ( ) ) ) ; assertEquals ( "<STR_LIT>" , annotated . getAnnotation ( Color . class ) . value ( ) ) ; assertTrue ( annotated . isAnnotationPresent ( Egg . class ) ) ; assertTrue ( annotated . getAnnotation ( Egg . class ) != null ) ; assertTrue ( contains ( Egg . class , annotated . getDeclaredAnnotations ( ) ) ) ; assertTrue ( contains ( Egg . class , annotated . getAnnotations ( ) ) ) ; assertTrue ( annotated . isAnnotationPresent ( Chicken . class ) ) ; assertTrue ( annotated . getAnnotation ( Chicken . class ) != null ) ; assertTrue ( ! contains ( Chicken . class , annotated . getDeclaredAnnotations ( ) ) ) ; assertTrue ( contains ( Chicken . class , annotated . getAnnotations ( ) ) ) ; assertEquals ( <NUM_LIT:1> , annotated . getDeclaredAnnotations ( ) . length ) ; assertEquals ( <NUM_LIT:3> , annotated . getAnnotations ( ) . length ) ; } { final java . lang . reflect . AnnotatedElement annotated = map . get ( "<STR_LIT>" ) ; assertNotNull ( annotated ) ; assertTrue ( annotated . isAnnotationPresent ( Color . class ) ) ; assertTrue ( annotated . getAnnotation ( Color . class ) != null ) ; assertTrue ( ! contains ( Color . class , annotated . getDeclaredAnnotations ( ) ) ) ; assertTrue ( contains ( Color . class , annotated . getAnnotations ( ) ) ) ; assertEquals ( "<STR_LIT>" , annotated . getAnnotation ( Color . class ) . value ( ) ) ; assertTrue ( annotated . isAnnotationPresent ( Egg . class ) ) ; assertTrue ( annotated . getAnnotation ( Egg . class ) != null ) ; assertTrue ( ! contains ( Egg . class , annotated . getDeclaredAnnotations ( ) ) ) ; assertTrue ( contains ( Egg . class , annotated . getAnnotations ( ) ) ) ; assertTrue ( annotated . isAnnotationPresent ( Chicken . class ) ) ; assertTrue ( annotated . getAnnotation ( Chicken . class ) != null ) ; assertTrue ( contains ( Chicken . class , annotated . getDeclaredAnnotations ( ) ) ) ; assertTrue ( contains ( Chicken . class , annotated . getAnnotations ( ) ) ) ; assertEquals ( <NUM_LIT:1> , annotated . getDeclaredAnnotations ( ) . length ) ; assertEquals ( <NUM_LIT:3> , annotated . getAnnotations ( ) . length ) ; } } private boolean contains ( Class < ? extends Annotation > type , Annotation [ ] annotations ) { for ( Annotation annotation : annotations ) { if ( type . isAssignableFrom ( annotation . annotationType ( ) ) ) return true ; } return false ; } @ Target ( { FIELD } ) @ Retention ( RUNTIME ) public static @ interface Color { String value ( ) default "<STR_LIT>" ; } @ Metatype @ Target ( { FIELD } ) @ Retention ( RUNTIME ) public static @ interface Red { public class $ { @ Red @ Color ( "<STR_LIT>" ) private Object field ; } } @ Metatype @ Target ( { FIELD } ) @ Retention ( RUNTIME ) public static @ interface Crimson { public class $ { @ Crimson @ Red private Object field ; } } @ Metatype @ Target ( { FIELD } ) @ Retention ( RUNTIME ) public static @ interface Green { public class $ { @ Green @ Color ( "<STR_LIT>" ) private Object field ; } } @ Metatype @ Target ( { FIELD } ) @ Retention ( RUNTIME ) public static @ interface DarkGreen { public class $ { @ DarkGreen @ Green private Object field ; } } @ Metatype @ Target ( { FIELD } ) @ Retention ( RUNTIME ) public static @ interface Forrest { public class $ { @ Forrest @ DarkGreen private Object field ; } } @ Metatype @ Target ( { FIELD } ) @ Retention ( RUNTIME ) public static @ interface Chicken { public class $ { @ Chicken @ Color ( "<STR_LIT>" ) @ Egg private Object field ; } } @ Metatype @ Target ( { FIELD } ) @ Retention ( RUNTIME ) public static @ interface Egg { public class $ { @ Egg @ Color ( "<STR_LIT>" ) @ Chicken private Object field ; } } public static class Square { @ Red private Object square ; } public static class Circle { @ Red @ Color ( "<STR_LIT>" ) private Object circle ; } public static class Triangle { @ Crimson private Object triangle ; } public static class Oval { @ Forrest private Object oval ; } public static class None { private Object none ; } public static class Store { @ Egg private Object store ; } public static class Farm { @ Chicken private Object farm ; } } </s> |
<s> package org . metatype ; import static java . lang . annotation . ElementType . ANNOTATION_TYPE ; import static java . lang . annotation . ElementType . TYPE ; import static java . lang . annotation . RetentionPolicy . RUNTIME ; import java . lang . annotation . Annotation ; import java . lang . annotation . Retention ; import java . lang . annotation . RetentionPolicy ; import java . lang . annotation . Target ; import junit . framework . TestCase ; import javax . annotation . Metaroot ; public class RootMetaAnnotatedClassTest extends TestCase { public void test ( ) throws Exception { { final java . lang . reflect . AnnotatedElement annotated = new MetaAnnotatedClass ( Circle . class ) ; assertNotNull ( annotated ) ; assertTrue ( annotated . isAnnotationPresent ( Color . class ) ) ; assertTrue ( annotated . getAnnotation ( Color . class ) != null ) ; assertTrue ( contains ( Color . class , annotated . getDeclaredAnnotations ( ) ) ) ; assertTrue ( contains ( Color . class , annotated . getAnnotations ( ) ) ) ; assertEquals ( "<STR_LIT>" , annotated . getAnnotation ( Color . class ) . value ( ) ) ; } { final java . lang . reflect . AnnotatedElement annotated = new MetaAnnotatedClass ( Square . class ) ; assertNotNull ( annotated ) ; assertTrue ( annotated . isAnnotationPresent ( Color . class ) ) ; assertTrue ( annotated . getAnnotation ( Color . class ) != null ) ; assertTrue ( ! contains ( Color . class , annotated . getDeclaredAnnotations ( ) ) ) ; assertTrue ( contains ( Color . class , annotated . getAnnotations ( ) ) ) ; assertEquals ( "<STR_LIT>" , annotated . getAnnotation ( Color . class ) . value ( ) ) ; assertTrue ( annotated . isAnnotationPresent ( Red . class ) ) ; assertTrue ( annotated . getAnnotation ( Red . class ) != null ) ; assertTrue ( contains ( Red . class , annotated . getDeclaredAnnotations ( ) ) ) ; assertTrue ( contains ( Red . class , annotated . getAnnotations ( ) ) ) ; } { final java . lang . reflect . AnnotatedElement annotated = new MetaAnnotatedClass ( Triangle . class ) ; assertNotNull ( annotated ) ; assertTrue ( annotated . isAnnotationPresent ( Color . class ) ) ; assertTrue ( annotated . getAnnotation ( Color . class ) != null ) ; assertTrue ( ! contains ( Color . class , annotated . getDeclaredAnnotations ( ) ) ) ; assertTrue ( contains ( Color . class , annotated . getAnnotations ( ) ) ) ; assertEquals ( "<STR_LIT>" , annotated . getAnnotation ( Color . class ) . value ( ) ) ; assertTrue ( annotated . isAnnotationPresent ( Red . class ) ) ; assertTrue ( annotated . getAnnotation ( Red . class ) != null ) ; assertTrue ( ! contains ( Red . class , annotated . getDeclaredAnnotations ( ) ) ) ; assertTrue ( contains ( Red . class , annotated . getAnnotations ( ) ) ) ; assertTrue ( annotated . isAnnotationPresent ( Crimson . class ) ) ; assertTrue ( annotated . getAnnotation ( Crimson . class ) != null ) ; assertTrue ( contains ( Crimson . class , annotated . getDeclaredAnnotations ( ) ) ) ; assertTrue ( contains ( Crimson . class , annotated . getAnnotations ( ) ) ) ; } { final java . lang . reflect . AnnotatedElement annotated = new MetaAnnotatedClass ( Store . class ) ; assertNotNull ( annotated ) ; assertTrue ( annotated . isAnnotationPresent ( Color . class ) ) ; assertTrue ( annotated . getAnnotation ( Color . class ) != null ) ; assertTrue ( ! contains ( Color . class , annotated . getDeclaredAnnotations ( ) ) ) ; assertTrue ( contains ( Color . class , annotated . getAnnotations ( ) ) ) ; assertEquals ( "<STR_LIT>" , annotated . getAnnotation ( Color . class ) . value ( ) ) ; assertTrue ( annotated . isAnnotationPresent ( Egg . class ) ) ; assertTrue ( annotated . getAnnotation ( Egg . class ) != null ) ; assertTrue ( contains ( Egg . class , annotated . getDeclaredAnnotations ( ) ) ) ; assertTrue ( contains ( Egg . class , annotated . getAnnotations ( ) ) ) ; assertTrue ( annotated . isAnnotationPresent ( Chicken . class ) ) ; assertTrue ( annotated . getAnnotation ( Chicken . class ) != null ) ; assertTrue ( ! contains ( Chicken . class , annotated . getDeclaredAnnotations ( ) ) ) ; assertTrue ( contains ( Chicken . class , annotated . getAnnotations ( ) ) ) ; } { final java . lang . reflect . AnnotatedElement annotated = new MetaAnnotatedClass ( Farm . class ) ; assertNotNull ( annotated ) ; assertTrue ( annotated . isAnnotationPresent ( Color . class ) ) ; assertTrue ( annotated . getAnnotation ( Color . class ) != null ) ; assertTrue ( ! contains ( Color . class , annotated . getDeclaredAnnotations ( ) ) ) ; assertTrue ( contains ( Color . class , annotated . getAnnotations ( ) ) ) ; assertEquals ( "<STR_LIT>" , annotated . getAnnotation ( Color . class ) . value ( ) ) ; assertTrue ( annotated . isAnnotationPresent ( Egg . class ) ) ; assertTrue ( annotated . getAnnotation ( Egg . class ) != null ) ; assertTrue ( ! contains ( Egg . class , annotated . getDeclaredAnnotations ( ) ) ) ; assertTrue ( contains ( Egg . class , annotated . getAnnotations ( ) ) ) ; assertTrue ( annotated . isAnnotationPresent ( Chicken . class ) ) ; assertTrue ( annotated . getAnnotation ( Chicken . class ) != null ) ; assertTrue ( contains ( Chicken . class , annotated . getDeclaredAnnotations ( ) ) ) ; assertTrue ( contains ( Chicken . class , annotated . getAnnotations ( ) ) ) ; } { final java . lang . reflect . AnnotatedElement annotated = new MetaAnnotatedClass ( Fake . class ) ; assertNotNull ( annotated ) ; assertTrue ( annotated . isAnnotationPresent ( NotMeta . class ) ) ; assertTrue ( annotated . getAnnotation ( NotMeta . class ) != null ) ; assertTrue ( contains ( NotMeta . class , annotated . getDeclaredAnnotations ( ) ) ) ; assertTrue ( contains ( NotMeta . class , annotated . getAnnotations ( ) ) ) ; assertFalse ( annotated . isAnnotationPresent ( Color . class ) ) ; assertTrue ( annotated . getAnnotation ( Color . class ) == null ) ; assertFalse ( contains ( Color . class , annotated . getDeclaredAnnotations ( ) ) ) ; assertFalse ( contains ( Color . class , annotated . getAnnotations ( ) ) ) ; } { final java . lang . reflect . AnnotatedElement annotated = new MetaAnnotatedClass ( None . class ) ; assertNotNull ( annotated ) ; assertFalse ( annotated . isAnnotationPresent ( NotMeta . class ) ) ; assertFalse ( annotated . isAnnotationPresent ( Stereotype . class ) ) ; assertTrue ( annotated . getAnnotation ( NotMeta . class ) == null ) ; assertTrue ( annotated . getAnnotation ( Stereotype . class ) == null ) ; assertEquals ( <NUM_LIT:0> , annotated . getDeclaredAnnotations ( ) . length ) ; assertEquals ( <NUM_LIT:0> , annotated . getAnnotations ( ) . length ) ; } } private boolean contains ( Class < ? extends Annotation > type , Annotation [ ] annotations ) { for ( Annotation annotation : annotations ) { if ( type . isAssignableFrom ( annotation . annotationType ( ) ) ) return true ; } return false ; } @ Metaroot @ Retention ( RetentionPolicy . RUNTIME ) @ Target ( ANNOTATION_TYPE ) public @ interface Stereotype { } @ Target ( value = { TYPE } ) @ Retention ( value = RUNTIME ) public static @ interface Color { String value ( ) default "<STR_LIT>" ; } @ Stereotype @ Color ( "<STR_LIT>" ) @ Target ( value = { TYPE } ) @ Retention ( value = RUNTIME ) public static @ interface Red { } @ Stereotype @ Red @ Target ( value = { TYPE } ) @ Retention ( value = RUNTIME ) public static @ interface Crimson { } @ Red @ Target ( value = { TYPE } ) @ Retention ( value = RUNTIME ) public static @ interface NotMeta { } @ Stereotype @ Color ( "<STR_LIT>" ) @ Chicken @ Target ( value = { TYPE } ) @ Retention ( value = RUNTIME ) public static @ interface Egg { } @ Stereotype @ Color ( "<STR_LIT>" ) @ Egg @ Target ( value = { TYPE } ) @ Retention ( value = RUNTIME ) public static @ interface Chicken { } @ Red public static class Square { } @ Red @ Color ( "<STR_LIT>" ) public static class Circle { } @ Crimson public static class Triangle { } public static class None { } @ NotMeta public static class Fake { } @ Egg public static class Store { } @ Chicken public static class Farm { } } </s> |
<s> package javax . annotation ; import java . lang . annotation . ElementType ; import java . lang . annotation . Retention ; import java . lang . annotation . RetentionPolicy ; import java . lang . annotation . Target ; @ Target ( ElementType . ANNOTATION_TYPE ) @ Retention ( RetentionPolicy . RUNTIME ) public @ interface Metaroot { } </s> |
<s> package javax . annotation ; import java . lang . annotation . ElementType ; import java . lang . annotation . Retention ; import java . lang . annotation . RetentionPolicy ; import java . lang . annotation . Target ; @ Metaroot @ Target ( ElementType . ANNOTATION_TYPE ) @ Retention ( RetentionPolicy . RUNTIME ) public @ interface Metatype { } </s> |
<s> package javax . ejb . meta ; import javax . ejb . TransactionAttribute ; import javax . ejb . TransactionAttributeType ; import java . lang . annotation . ElementType ; import java . lang . annotation . Retention ; import java . lang . annotation . RetentionPolicy ; import java . lang . annotation . Target ; import javax . annotation . Metatype ; @ TransactionAttribute ( TransactionAttributeType . SUPPORTS ) @ Metatype @ Target ( { ElementType . METHOD , ElementType . TYPE } ) @ Retention ( RetentionPolicy . RUNTIME ) public @ interface TxSupports { } </s> |
<s> package javax . ejb . meta ; import javax . ejb . Lock ; import javax . ejb . LockType ; import java . lang . annotation . ElementType ; import java . lang . annotation . Retention ; import java . lang . annotation . RetentionPolicy ; import java . lang . annotation . Target ; import javax . annotation . Metatype ; @ Lock ( LockType . READ ) @ Metatype @ Target ( { ElementType . METHOD , ElementType . TYPE } ) @ Retention ( RetentionPolicy . RUNTIME ) public @ interface ReadLock { } </s> |
<s> package javax . ejb . meta ; import javax . ejb . AccessTimeout ; import java . lang . annotation . ElementType ; import java . lang . annotation . Retention ; import java . lang . annotation . RetentionPolicy ; import java . lang . annotation . Target ; import javax . annotation . Metatype ; @ AccessTimeout ( - <NUM_LIT:1> ) @ Metatype @ Target ( { ElementType . METHOD , ElementType . TYPE } ) @ Retention ( RetentionPolicy . RUNTIME ) public @ interface AwaitForever { } </s> |
<s> package javax . ejb . meta ; import javax . ejb . TransactionAttribute ; import javax . ejb . TransactionAttributeType ; import java . lang . annotation . ElementType ; import java . lang . annotation . Retention ; import java . lang . annotation . RetentionPolicy ; import java . lang . annotation . Target ; import javax . annotation . Metatype ; @ TransactionAttribute ( TransactionAttributeType . REQUIRES_NEW ) @ Metatype @ Target ( { ElementType . METHOD , ElementType . TYPE } ) @ Retention ( RetentionPolicy . RUNTIME ) public @ interface TxRequiresNew { } </s> |
<s> package javax . ejb . meta ; import javax . ejb . Schedule ; import java . lang . annotation . ElementType ; import java . lang . annotation . Retention ; import java . lang . annotation . RetentionPolicy ; import java . lang . annotation . Target ; import javax . annotation . Metatype ; @ Metatype @ Target ( { ElementType . METHOD } ) @ Retention ( RetentionPolicy . RUNTIME ) public @ interface Yearly { public static class $ { @ Yearly @ Schedule ( second = "<STR_LIT:0>" , minute = "<STR_LIT:0>" , hour = "<STR_LIT:0>" , month = "<STR_LIT:*>" , year = "<STR_LIT:*>" ) public void method ( ) { } } } </s> |
<s> package javax . ejb . meta ; import javax . ejb . Schedule ; import java . lang . annotation . ElementType ; import java . lang . annotation . Retention ; import java . lang . annotation . RetentionPolicy ; import java . lang . annotation . Target ; import javax . annotation . Metatype ; @ Metatype @ Target ( { ElementType . METHOD } ) @ Retention ( RetentionPolicy . RUNTIME ) public @ interface Weekly { public static class $ { @ Weekly @ Schedule ( second = "<STR_LIT:0>" , minute = "<STR_LIT:0>" , hour = "<STR_LIT:0>" , month = "<STR_LIT:*>" , dayOfWeek = "<STR_LIT:0>" , year = "<STR_LIT:*>" ) public void method ( ) { } } } </s> |
<s> package javax . ejb . meta ; import javax . ejb . TransactionAttribute ; import javax . ejb . TransactionAttributeType ; import java . lang . annotation . ElementType ; import java . lang . annotation . Retention ; import java . lang . annotation . RetentionPolicy ; import java . lang . annotation . Target ; import javax . annotation . Metatype ; @ TransactionAttribute ( TransactionAttributeType . NOT_SUPPORTED ) @ Metatype @ Target ( { ElementType . METHOD , ElementType . TYPE } ) @ Retention ( RetentionPolicy . RUNTIME ) public @ interface TxNotSupported { } </s> |
<s> package javax . ejb . meta ; import javax . ejb . ConcurrencyManagement ; import javax . ejb . ConcurrencyManagementType ; import java . lang . annotation . ElementType ; import java . lang . annotation . Retention ; import java . lang . annotation . RetentionPolicy ; import java . lang . annotation . Target ; import javax . annotation . Metatype ; @ ConcurrencyManagement ( ConcurrencyManagementType . BEAN ) @ Metatype @ Target ( { ElementType . TYPE } ) @ Retention ( RetentionPolicy . RUNTIME ) public @ interface BeanManagedConcurrency { } </s> |
<s> package javax . ejb . meta ; import javax . ejb . TransactionAttribute ; import javax . ejb . TransactionAttributeType ; import java . lang . annotation . ElementType ; import java . lang . annotation . Retention ; import java . lang . annotation . RetentionPolicy ; import java . lang . annotation . Target ; import javax . annotation . Metatype ; @ TransactionAttribute ( TransactionAttributeType . MANDATORY ) @ Metatype @ Target ( { ElementType . METHOD , ElementType . TYPE } ) @ Retention ( RetentionPolicy . RUNTIME ) public @ interface TxMandatory { } </s> |
<s> package javax . ejb . meta ; import javax . ejb . Schedule ; import java . lang . annotation . ElementType ; import java . lang . annotation . Retention ; import java . lang . annotation . RetentionPolicy ; import java . lang . annotation . Target ; import javax . annotation . Metatype ; @ Metatype @ Target ( { ElementType . METHOD } ) @ Retention ( RetentionPolicy . RUNTIME ) public @ interface Hourly { public static class $ { @ Hourly @ Schedule ( second = "<STR_LIT:0>" , minute = "<STR_LIT:0>" , hour = "<STR_LIT:*>" , month = "<STR_LIT:*>" , dayOfWeek = "<STR_LIT:*>" , year = "<STR_LIT:*>" ) public void method ( ) { } } } </s> |
<s> package javax . ejb . meta ; import java . lang . annotation . ElementType ; import java . lang . annotation . Retention ; import java . lang . annotation . RetentionPolicy ; import java . lang . annotation . Target ; import javax . annotation . Metatype ; @ Metatype @ Target ( { ElementType . METHOD } ) @ Retention ( RetentionPolicy . RUNTIME ) public @ interface Annually { public static class $ { @ Annually @ Yearly public void method ( ) { } } } </s> |
<s> package javax . ejb . meta ; import java . lang . annotation . ElementType ; import java . lang . annotation . Retention ; import java . lang . annotation . RetentionPolicy ; import java . lang . annotation . Target ; import javax . annotation . Metatype ; @ ContainerManagedConcurrency @ Metatype @ Target ( { ElementType . TYPE } ) @ Retention ( RetentionPolicy . RUNTIME ) public @ interface ManagedConcurrency { } </s> |
<s> package javax . ejb . meta ; import javax . ejb . Schedule ; import java . lang . annotation . ElementType ; import java . lang . annotation . Retention ; import java . lang . annotation . RetentionPolicy ; import java . lang . annotation . Target ; import javax . annotation . Metatype ; @ Metatype @ Target ( { ElementType . METHOD } ) @ Retention ( RetentionPolicy . RUNTIME ) public @ interface Daily { public static class $ { @ Daily @ Schedule ( second = "<STR_LIT:0>" , minute = "<STR_LIT:0>" , hour = "<STR_LIT:0>" , month = "<STR_LIT:*>" , dayOfWeek = "<STR_LIT:*>" , year = "<STR_LIT:*>" ) public void method ( ) { } } } </s> |
<s> package javax . ejb . meta ; import javax . ejb . Schedule ; import java . lang . annotation . ElementType ; import java . lang . annotation . Retention ; import java . lang . annotation . RetentionPolicy ; import java . lang . annotation . Target ; import javax . annotation . Metatype ; @ Metatype @ Target ( { ElementType . METHOD } ) @ Retention ( RetentionPolicy . RUNTIME ) public @ interface Monthly { public static class $ { @ Monthly @ Schedule ( second = "<STR_LIT:0>" , minute = "<STR_LIT:0>" , hour = "<STR_LIT:0>" , month = "<STR_LIT:*>" , dayOfMonth = "<STR_LIT:1>" , year = "<STR_LIT:*>" ) public void method ( ) { } } } </s> |
<s> package javax . ejb . meta ; import javax . ejb . AccessTimeout ; import javax . ejb . TransactionAttribute ; import javax . ejb . TransactionAttributeType ; import java . lang . annotation . ElementType ; import java . lang . annotation . Retention ; import java . lang . annotation . RetentionPolicy ; import java . lang . annotation . Target ; import javax . annotation . Metatype ; @ AccessTimeout ( <NUM_LIT:0> ) @ Metatype @ Target ( { ElementType . METHOD , ElementType . TYPE } ) @ Retention ( RetentionPolicy . RUNTIME ) public @ interface AwaitNever { } </s> |
<s> package javax . ejb . meta ; import javax . ejb . Lock ; import javax . ejb . LockType ; import java . lang . annotation . ElementType ; import java . lang . annotation . Retention ; import java . lang . annotation . RetentionPolicy ; import java . lang . annotation . Target ; import javax . annotation . Metatype ; @ Lock ( LockType . WRITE ) @ Metatype @ Target ( { ElementType . METHOD , ElementType . TYPE } ) @ Retention ( RetentionPolicy . RUNTIME ) public @ interface WriteLock { } </s> |
<s> package javax . ejb . meta ; import java . lang . annotation . ElementType ; import java . lang . annotation . Retention ; import java . lang . annotation . RetentionPolicy ; import java . lang . annotation . Target ; import javax . annotation . Metatype ; @ Metatype @ Target ( { ElementType . METHOD } ) @ Retention ( RetentionPolicy . RUNTIME ) public @ interface Midnight { public static class $ { @ Midnight @ Daily public void method ( ) { } } } </s> |
<s> package javax . ejb . meta ; import javax . ejb . TransactionAttribute ; import javax . ejb . TransactionAttributeType ; import java . lang . annotation . ElementType ; import java . lang . annotation . Retention ; import java . lang . annotation . RetentionPolicy ; import java . lang . annotation . Target ; import javax . annotation . Metatype ; @ TransactionAttribute ( TransactionAttributeType . REQUIRED ) @ Metatype @ Target ( { ElementType . METHOD , ElementType . TYPE } ) @ Retention ( RetentionPolicy . RUNTIME ) public @ interface TxRequired { } </s> |
<s> package javax . ejb . meta ; import java . lang . annotation . ElementType ; import java . lang . annotation . Retention ; import java . lang . annotation . RetentionPolicy ; import java . lang . annotation . Target ; import javax . annotation . Metatype ; @ ContainerManagedTransactions @ Metatype @ Target ( { ElementType . TYPE } ) @ Retention ( RetentionPolicy . RUNTIME ) public @ interface ManagedTransactions { } </s> |
<s> package javax . ejb . meta ; import javax . ejb . TransactionAttribute ; import javax . ejb . TransactionAttributeType ; import java . lang . annotation . ElementType ; import java . lang . annotation . Retention ; import java . lang . annotation . RetentionPolicy ; import java . lang . annotation . Target ; import javax . annotation . Metatype ; @ TransactionAttribute ( TransactionAttributeType . NEVER ) @ Metatype @ Target ( { ElementType . METHOD , ElementType . TYPE } ) @ Retention ( RetentionPolicy . RUNTIME ) public @ interface TxNever { } </s> |
<s> package javax . ejb . meta ; import javax . ejb . TransactionManagement ; import javax . ejb . TransactionManagementType ; import java . lang . annotation . ElementType ; import java . lang . annotation . Retention ; import java . lang . annotation . RetentionPolicy ; import java . lang . annotation . Target ; import javax . annotation . Metatype ; @ TransactionManagement ( TransactionManagementType . CONTAINER ) @ Metatype @ Target ( { ElementType . TYPE } ) @ Retention ( RetentionPolicy . RUNTIME ) public @ interface ContainerManagedTransactions { } </s> |
<s> package javax . ejb . meta ; import javax . ejb . TransactionManagement ; import javax . ejb . TransactionManagementType ; import java . lang . annotation . ElementType ; import java . lang . annotation . Retention ; import java . lang . annotation . RetentionPolicy ; import java . lang . annotation . Target ; import javax . annotation . Metatype ; @ TransactionManagement ( TransactionManagementType . BEAN ) @ Metatype @ Target ( { ElementType . TYPE } ) @ Retention ( RetentionPolicy . RUNTIME ) public @ interface BeanManagedTransactions { } </s> |
<s> package javax . ejb . meta ; import javax . ejb . ConcurrencyManagement ; import javax . ejb . ConcurrencyManagementType ; import java . lang . annotation . ElementType ; import java . lang . annotation . Retention ; import java . lang . annotation . RetentionPolicy ; import java . lang . annotation . Target ; import javax . annotation . Metatype ; @ ConcurrencyManagement ( ConcurrencyManagementType . CONTAINER ) @ Metatype @ Target ( { ElementType . TYPE } ) @ Retention ( RetentionPolicy . RUNTIME ) public @ interface ContainerManagedConcurrency { } </s> |
<s> package smartrics . rest . fitnesse . fixture ; import java . io . ByteArrayOutputStream ; import java . io . PrintStream ; import smartrics . rest . fitnesse . fixture . support . CellFormatter ; import smartrics . rest . fitnesse . fixture . support . CellWrapper ; import smartrics . rest . fitnesse . fixture . support . RestDataTypeAdapter ; import smartrics . rest . fitnesse . fixture . support . Tools ; public class SlimFormatter implements CellFormatter < String > { private int minLenForToggle = - <NUM_LIT:1> ; private boolean displayActual ; public SlimFormatter ( ) { } @ Override public void setDisplayActual ( boolean d ) { this . displayActual = d ; } @ Override public void setMinLenghtForToggleCollapse ( int minLen ) { this . minLenForToggle = minLen ; } public boolean isDisplayActual ( ) { return displayActual ; } @ Override public void exception ( CellWrapper < String > cell , String exceptionMessage ) { cell . body ( "<STR_LIT>" + exceptionMessage ) ; } @ Override public void exception ( CellWrapper < String > cell , Throwable exception ) { ByteArrayOutputStream out = new ByteArrayOutputStream ( ) ; PrintStream ps = new PrintStream ( out ) ; exception . printStackTrace ( ps ) ; String m = Tools . toHtml ( cell . getWrapped ( ) + "<STR_LIT>" ) + Tools . toCode ( Tools . toHtml ( out . toString ( ) ) ) ; cell . body ( "<STR_LIT>" + m ) ; } @ Override public void check ( CellWrapper < String > expected , RestDataTypeAdapter actual ) { if ( null == expected . body ( ) || "<STR_LIT>" . equals ( expected . body ( ) ) ) { if ( actual . get ( ) == null ) { return ; } else { expected . body ( gray ( actual . get ( ) . toString ( ) ) ) ; return ; } } if ( actual . get ( ) != null && actual . equals ( expected . body ( ) , actual . get ( ) . toString ( ) ) ) { right ( expected , actual ) ; } else { wrong ( expected , actual ) ; } } @ Override public String label ( String string ) { return Tools . toHtmlLabel ( string ) ; } @ Override public void wrong ( CellWrapper < String > expected , RestDataTypeAdapter ta ) { String expectedContent = expected . body ( ) ; expected . body ( Tools . makeContentForWrongCell ( expectedContent , ta , this , minLenForToggle ) ) ; expected . body ( "<STR_LIT>" + expected . body ( ) ) ; } @ Override public void right ( CellWrapper < String > expected , RestDataTypeAdapter typeAdapter ) { expected . body ( "<STR_LIT>" + Tools . makeContentForRightCell ( expected . body ( ) , typeAdapter , this , minLenForToggle ) ) ; } @ Override public String gray ( String string ) { return "<STR_LIT>" + Tools . toHtml ( string ) ; } @ Override public void asLink ( CellWrapper < String > cell , String link , String text ) { cell . body ( "<STR_LIT>" + Tools . toHtmlLink ( link , text ) ) ; } @ Override public String fromRaw ( String text ) { return Tools . fromHtml ( text ) ; } } </s> |
<s> package smartrics . rest . fitnesse . fixture ; import java . io . BufferedReader ; import java . io . File ; import java . io . FileNotFoundException ; import java . io . FileReader ; import java . io . IOException ; import org . apache . commons . logging . Log ; import org . apache . commons . logging . LogFactory ; import util . Maybe ; import fitnesse . html . HtmlTag ; import fitnesse . wikitext . parser . Matcher ; import fitnesse . wikitext . parser . Parser ; import fitnesse . wikitext . parser . Rule ; import fitnesse . wikitext . parser . Symbol ; import fitnesse . wikitext . parser . SymbolProvider ; import fitnesse . wikitext . parser . SymbolType ; import fitnesse . wikitext . parser . Translation ; import fitnesse . wikitext . parser . Translator ; public class SvgImage extends SymbolType implements Rule , Translation { static final Log LOG = LogFactory . getLog ( SvgImage . class ) ; private enum Mode { inline , embed ( "<STR_LIT>" , "<STR_LIT:src>" , "<STR_LIT>" ) , object ( "<STR_LIT>" , "<STR_LIT:data>" , "<STR_LIT>" ) , iframe ( "<STR_LIT>" , "<STR_LIT:src>" ) , img ( "<STR_LIT>" , "<STR_LIT:src>" ) , anchor ( "<STR_LIT:a>" , "<STR_LIT>" ) ; public String toString ( String stuff ) { if ( this . equals ( inline ) ) { return stuff ; } String s = "<STR_LIT>" ; if ( otherAttr != null ) { s = otherAttr ; } return "<STR_LIT:<>" + tag + "<STR_LIT:U+0020>" + srcAttr + "<STR_LIT>" + stuff + "<STR_LIT>" + s + "<STR_LIT>" ; } private Mode ( ) { this ( null , null , null ) ; } private Mode ( String tag , String srcAttr ) { this ( tag , srcAttr , null ) ; } private Mode ( String tag , String srcAttr , String otherAttr ) { this . tag = tag ; this . srcAttr = srcAttr ; this . otherAttr = otherAttr ; } private String tag ; private String srcAttr ; private String otherAttr ; } private Mode defaultMode = Mode . inline ; public SvgImage ( ) { super ( "<STR_LIT>" ) ; wikiMatcher ( new Matcher ( ) . string ( "<STR_LIT>" ) ) ; htmlTranslation ( this ) ; wikiRule ( this ) ; } public Maybe < Symbol > parse ( Symbol current , Parser parser ) { Symbol targetList = parser . parseToEnds ( - <NUM_LIT:1> , SymbolProvider . pathRuleProvider , new SymbolType [ ] { SymbolType . Newline } ) ; return new Maybe < Symbol > ( current . add ( targetList ) ) ; } public String toTarget ( Translator translator , Symbol symbol ) { String symContent = symbol . getContent ( ) ; String target = symContent + translator . translate ( symbol . childAt ( <NUM_LIT:0> ) ) ; return toTarget ( translator , target , symbol ) ; } public String toTarget ( Translator translator , String body , Symbol args ) { Symbol symbol = getPathSymbol ( args ) ; if ( symbol == null ) { return error ( "<STR_LIT>" ) ; } String line = translator . translate ( symbol ) ; line = line . replaceAll ( "<STR_LIT>" , "<STR_LIT:U+0020>" ) . trim ( ) ; String [ ] parts = line . split ( "<STR_LIT:U+0020>" ) ; String location = null ; Mode mode = defaultMode ; if ( parts . length > <NUM_LIT:0> ) { location = parts [ <NUM_LIT:0> ] ; } if ( parts . length > <NUM_LIT:1> ) { for ( String part : parts ) { if ( part . contains ( "<STR_LIT>" ) ) { mode = parseMode ( part ) ; } } } return inlineSvg ( mode , location ) ; } private Mode parseMode ( String s ) { String mString = null ; Mode mode = defaultMode ; try { mString = s . trim ( ) ; String [ ] subParts = mString . split ( "<STR_LIT:=>" ) ; mode = Enum . valueOf ( Mode . class , subParts [ <NUM_LIT:1> ] . trim ( ) ) ; } catch ( IllegalArgumentException e ) { throw new IllegalArgumentException ( "<STR_LIT>" + mString ) ; } return mode ; } private Symbol getPathSymbol ( Symbol args ) { if ( args . getChildren ( ) . size ( ) > <NUM_LIT:0> ) { return args . childAt ( <NUM_LIT:0> ) ; } return null ; } private String inlineSvg ( Mode tag , String location ) { if ( location == null ) { return error ( "<STR_LIT>" ) ; } if ( tag . equals ( Mode . inline ) ) { String content = read ( location ) ; return tag . toString ( content ) ; } else { return tag . toString ( location ) ; } } private String read ( String path ) { String loc = path . trim ( ) ; if ( loc . startsWith ( "<STR_LIT>" ) ) { loc = "<STR_LIT>" + path . trim ( ) ; } String content = null ; File f = new File ( loc ) ; try { if ( f . exists ( ) ) { content = readFile ( f ) ; } else { content = error ( "<STR_LIT>" + f . getAbsolutePath ( ) + "<STR_LIT>" + path ) ; } } catch ( FileNotFoundException e ) { content = error ( "<STR_LIT>" + loc + "<STR_LIT>" + path + "<STR_LIT>" + e . getMessage ( ) ) ; } catch ( RuntimeException e ) { content = error ( "<STR_LIT>" + loc + "<STR_LIT>" + path ) ; } return content ; } private String readFile ( File f ) throws FileNotFoundException { FileReader reader = new FileReader ( f ) ; BufferedReader r = new BufferedReader ( reader ) ; StringBuilder sb = new StringBuilder ( ) ; String line ; LOG . debug ( "<STR_LIT>" + f . getAbsolutePath ( ) ) ; try { while ( ( line = r . readLine ( ) ) != null ) { sb . append ( line ) ; } } catch ( IOException e ) { throw new IllegalArgumentException ( "<STR_LIT>" , e ) ; } finally { try { r . close ( ) ; } catch ( IOException e ) { LOG . debug ( "<STR_LIT>" + f . getAbsolutePath ( ) ) ; } } return sb . toString ( ) ; } private String error ( String string ) { HtmlTag tag = new HtmlTag ( "<STR_LIT:p>" ) ; tag . addAttribute ( "<STR_LIT>" , "<STR_LIT>" ) ; tag . add ( string ) ; return tag . htmlInline ( ) ; } } </s> |
<s> package smartrics . rest . fitnesse . fixture ; import smartrics . rest . fitnesse . fixture . support . CellFormatter ; import smartrics . rest . fitnesse . fixture . support . CellWrapper ; import smartrics . rest . fitnesse . fixture . support . RestDataTypeAdapter ; import smartrics . rest . fitnesse . fixture . support . Tools ; import fit . ActionFixture ; import fit . Parse ; import fit . exception . FitFailureException ; public class FitFormatter implements CellFormatter < Parse > { private ActionFixture fixture ; private boolean displayActual ; private int minLenForToggle = - <NUM_LIT:1> ; public void setActionFixtureDelegate ( ActionFixture f ) { this . fixture = f ; } @ Override public boolean isDisplayActual ( ) { return displayActual ; } @ Override public void setMinLenghtForToggleCollapse ( int minLen ) { this . minLenForToggle = minLen ; } @ Override public void setDisplayActual ( boolean d ) { this . displayActual = d ; } @ Override public void exception ( CellWrapper < Parse > cell , String exceptionMessage ) { Parse wrapped = cell . getWrapped ( ) ; fixture . exception ( wrapped , new FitFailureException ( exceptionMessage ) ) ; } @ Override public void exception ( CellWrapper < Parse > cell , Throwable exception ) { Parse wrapped = cell . getWrapped ( ) ; fixture . exception ( wrapped , exception ) ; } @ Override public void check ( CellWrapper < Parse > valueCell , RestDataTypeAdapter adapter ) { valueCell . body ( Tools . toHtml ( valueCell . body ( ) ) ) ; fixture . check ( valueCell . getWrapped ( ) , adapter ) ; } @ Override public String label ( String string ) { return ActionFixture . label ( string ) ; } @ Override public void wrong ( CellWrapper < Parse > expected , RestDataTypeAdapter typeAdapter ) { String expectedContent = expected . body ( ) ; String body = Tools . makeContentForWrongCell ( expectedContent , typeAdapter , this , minLenForToggle ) ; expected . body ( body ) ; fixture . wrong ( expected . getWrapped ( ) ) ; } @ Override public void right ( CellWrapper < Parse > expected , RestDataTypeAdapter typeAdapter ) { String expectedContent = expected . body ( ) ; expected . body ( Tools . makeContentForRightCell ( expectedContent , typeAdapter , this , minLenForToggle ) ) ; fixture . right ( expected . getWrapped ( ) ) ; } @ Override public String gray ( String string ) { return ActionFixture . gray ( Tools . toHtml ( string ) ) ; } @ Override public void asLink ( CellWrapper < Parse > cell , String link , String text ) { cell . body ( Tools . toHtmlLink ( link , text ) ) ; } @ Override public String fromRaw ( String text ) { return text ; } } </s> |
<s> package smartrics . rest . fitnesse . fixture ; import java . util . Map ; import org . slf4j . Logger ; import org . slf4j . LoggerFactory ; import smartrics . rest . fitnesse . fixture . RestFixture . Runner ; import smartrics . rest . fitnesse . fixture . support . CellFormatter ; import smartrics . rest . fitnesse . fixture . support . Config ; import smartrics . rest . fitnesse . fixture . support . RowWrapper ; import smartrics . rest . fitnesse . fixture . support . Tools ; import smartrics . rest . fitnesse . fixture . support . Url ; import fit . ActionFixture ; import fit . Parse ; public class FitRestFixture extends ActionFixture { private static final Logger LOG = LoggerFactory . getLogger ( FitRestFixture . class ) ; private RestFixture restFixture ; public String toString ( ) { return restFixture . toString ( ) ; } public String getLastEvaluation ( ) { return restFixture . getLastEvaluation ( ) ; } public String getBaseUrl ( ) { return restFixture . getBaseUrl ( ) ; } public void setBaseUrl ( Url url ) { restFixture . setBaseUrl ( url ) ; } public Map < String , String > getDefaultHeaders ( ) { return restFixture . getDefaultHeaders ( ) ; } public CellFormatter < ? > getFormatter ( ) { return restFixture . getFormatter ( ) ; } public void setMultipartFileName ( ) { restFixture . setMultipartFileName ( ) ; } public String getMultipartFileName ( ) { return restFixture . getMultipartFileName ( ) ; } public void setFileName ( ) { restFixture . setFileName ( ) ; } public String getFileName ( ) { return restFixture . getFileName ( ) ; } public void setMultipartFileParameterName ( ) { restFixture . setMultipartFileParameterName ( ) ; } public String getMultipartFileParameterName ( ) { return restFixture . getMultipartFileParameterName ( ) ; } public void setBody ( ) { restFixture . setBody ( ) ; } public void setHeader ( ) { restFixture . setHeader ( ) ; } public void setHeaders ( ) { restFixture . setHeaders ( ) ; } public void setHeaders ( String headers ) { restFixture . setHeaders ( headers ) ; } public void PUT ( ) { restFixture . PUT ( ) ; } public void GET ( ) { restFixture . GET ( ) ; } public void DELETE ( ) { restFixture . DELETE ( ) ; } public void POST ( ) { restFixture . POST ( ) ; } public void let ( ) { restFixture . let ( ) ; } public void comment ( ) { restFixture . comment ( ) ; } public void evalJs ( ) { restFixture . evalJs ( ) ; } public void processRow ( RowWrapper < ? > currentRow ) { restFixture . processRow ( currentRow ) ; } public Map < String , String > getHeaders ( ) { return restFixture . getHeaders ( ) ; } @ Override @ SuppressWarnings ( { "<STR_LIT:rawtypes>" , "<STR_LIT:unchecked>" } ) public void doCells ( Parse parse ) { restFixture = new RestFixture ( ) ; restFixture . setConfig ( Config . getConfig ( getConfigNameFromArgs ( ) ) ) ; String url = getBaseUrlFromArgs ( ) ; if ( url != null ) { restFixture . setBaseUrl ( new Url ( Tools . fromSimpleTag ( url ) ) ) ; } restFixture . initialize ( Runner . FIT ) ; ( ( FitFormatter ) restFixture . getFormatter ( ) ) . setActionFixtureDelegate ( this ) ; RowWrapper currentRow = new FitRow ( parse ) ; try { restFixture . processRow ( currentRow ) ; } catch ( Exception exception ) { LOG . error ( "<STR_LIT>" + currentRow . getCell ( <NUM_LIT:0> ) . text ( ) , exception ) ; restFixture . getFormatter ( ) . exception ( currentRow . getCell ( <NUM_LIT:0> ) , exception ) ; } } protected String getConfigNameFromArgs ( ) { if ( args . length >= <NUM_LIT:2> ) { return args [ <NUM_LIT:1> ] ; } return null ; } protected String getBaseUrlFromArgs ( ) { if ( args . length > <NUM_LIT:0> ) { return args [ <NUM_LIT:0> ] ; } return null ; } public Config getConfig ( ) { return restFixture . getConfig ( ) ; } } </s> |
<s> package smartrics . rest . fitnesse . fixture ; import smartrics . rest . fitnesse . fixture . support . CellWrapper ; public class SlimCell implements CellWrapper < String > { private String cell ; public SlimCell ( String c ) { this . cell = c ; } @ Override public String text ( ) { return cell ; } @ Override public void body ( String string ) { cell = string ; } @ Override public String body ( ) { return cell ; } @ Override public void addToBody ( String string ) { cell = cell + string ; } @ Override public String getWrapped ( ) { return cell ; } } </s> |
<s> package smartrics . rest . fitnesse . fixture ; import org . apache . commons . httpclient . HttpClient ; import org . apache . commons . httpclient . HttpURL ; import org . apache . commons . httpclient . URI ; import org . apache . commons . httpclient . URIException ; import smartrics . rest . client . RestClient ; import smartrics . rest . client . RestClientImpl ; import smartrics . rest . client . RestRequest ; import smartrics . rest . fitnesse . fixture . RestFixture . Runner ; import smartrics . rest . fitnesse . fixture . support . BodyTypeAdapter ; import smartrics . rest . fitnesse . fixture . support . BodyTypeAdapterFactory ; import smartrics . rest . fitnesse . fixture . support . CellFormatter ; import smartrics . rest . fitnesse . fixture . support . Config ; import smartrics . rest . fitnesse . fixture . support . ContentType ; import smartrics . rest . fitnesse . fixture . support . HttpClientBuilder ; public class PartsFactory { public RestClient buildRestClient ( final Config config ) { HttpClient httpClient = new HttpClientBuilder ( ) . createHttpClient ( config ) ; return new RestClientImpl ( httpClient ) { @ Override protected URI createUri ( String uriString , boolean escaped ) throws URIException { boolean useNewHttpUriFactory = config . getAsBoolean ( "<STR_LIT>" , false ) ; if ( useNewHttpUriFactory ) { return new HttpURL ( uriString ) ; } return super . createUri ( uriString , escaped ) ; } @ Override public String getMethodClassnameFromMethodName ( String mName ) { boolean useOverriddenHttpMethodImpl = config . getAsBoolean ( "<STR_LIT>" , false ) ; if ( useOverriddenHttpMethodImpl ) { return String . format ( "<STR_LIT>" , mName ) ; } return super . getMethodClassnameFromMethodName ( mName ) ; } } ; } public RestRequest buildRestRequest ( ) { return new RestRequest ( ) ; } public CellFormatter < ? > buildCellFormatter ( Runner runner ) { if ( runner == null ) { throw new IllegalArgumentException ( "<STR_LIT>" ) ; } if ( Runner . SLIM . equals ( runner ) ) { return new SlimFormatter ( ) ; } if ( Runner . FIT . equals ( runner ) ) { return new FitFormatter ( ) ; } throw new IllegalStateException ( "<STR_LIT>" + runner . name ( ) + "<STR_LIT>" ) ; } public BodyTypeAdapter buildBodyTypeAdapter ( ContentType ct , String charset ) { return BodyTypeAdapterFactory . getBodyTypeAdapter ( ct , charset ) ; } } </s> |
<s> package smartrics . rest . fitnesse . fixture . support ; import java . util . Collection ; import fit . Parse ; public abstract class BodyTypeAdapter extends RestDataTypeAdapter { private String charset ; public BodyTypeAdapter ( ) { super ( ) ; } protected void setCharset ( String charset ) { this . charset = charset ; } public String getCharset ( ) { return charset ; } protected boolean checkNoBody ( final Object value ) { if ( value == null ) { return true ; } if ( value instanceof Collection ) { return ( ( Collection < ? > ) value ) . size ( ) == <NUM_LIT:0> ; } String s = value . toString ( ) ; if ( value instanceof Parse ) { s = ( ( Parse ) value ) . text ( ) . trim ( ) ; } return checkNoBodyForString ( s ) ; } private boolean checkNoBodyForString ( final String value ) { return "<STR_LIT>" . equals ( value . trim ( ) ) || "<STR_LIT>" . equals ( value . trim ( ) ) ; } public abstract String toXmlString ( String content ) ; @ Override public String toString ( final Object obj ) { if ( obj == null || obj . toString ( ) . trim ( ) . equals ( "<STR_LIT>" ) ) { return "<STR_LIT>" ; } return obj . toString ( ) ; } } </s> |
<s> package smartrics . rest . fitnesse . fixture . support ; public interface RowWrapper < E > { CellWrapper < E > getCell ( int c ) ; int size ( ) ; CellWrapper < E > removeCell ( int c ) ; } </s> |
<s> package smartrics . rest . fitnesse . fixture . support ; import java . util . regex . Pattern ; import java . util . regex . Matcher ; import java . util . regex . PatternSyntaxException ; import fit . Parse ; public class TextBodyTypeAdapter extends BodyTypeAdapter { @ Override public boolean equals ( Object exp , Object act ) { if ( exp == null || act == null ) { return false ; } String expected = exp . toString ( ) ; if ( exp instanceof Parse ) { expected = ( ( Parse ) exp ) . text ( ) ; } String actual = ( String ) act ; try { Pattern p = Pattern . compile ( expected ) ; Matcher m = p . matcher ( actual ) ; if ( ! m . matches ( ) && ! m . find ( ) ) { addError ( "<STR_LIT>" + expected ) ; } } catch ( PatternSyntaxException e ) { if ( ! expected . equals ( actual ) ) { addError ( "<STR_LIT>" + expected ) ; } } return getErrors ( ) . size ( ) == <NUM_LIT:0> ; } @ Override public Object parse ( String s ) { if ( s == null ) { return "<STR_LIT:null>" ; } return s . trim ( ) ; } @ Override public String toXmlString ( String content ) { return "<STR_LIT>" + content + "<STR_LIT>" ; } } </s> |
<s> package smartrics . rest . fitnesse . fixture . support ; import java . util . ArrayList ; import java . util . Collection ; import java . util . List ; import smartrics . rest . client . RestData . Header ; public class HeadersTypeAdapter extends RestDataTypeAdapter { @ Override @ SuppressWarnings ( "<STR_LIT:unchecked>" ) public boolean equals ( Object expectedObj , Object actualObj ) { if ( expectedObj == null || actualObj == null ) { return false ; } Collection < Header > expected = ( Collection < Header > ) expectedObj ; Collection < Header > actual = ( Collection < Header > ) actualObj ; for ( Header k : expected ) { Header aHdr = find ( actual , k ) ; if ( aHdr == null ) { addError ( "<STR_LIT>" + k . getName ( ) + "<STR_LIT:U+0020:U+0020>" + k . getValue ( ) + "<STR_LIT:]>" ) ; } } return getErrors ( ) . size ( ) == <NUM_LIT:0> ; } private Header find ( Collection < Header > actual , Header k ) { for ( Header h : actual ) { boolean nameMatches = h . getName ( ) . equals ( k . getName ( ) ) ; boolean valueMatches = Tools . regex ( h . getValue ( ) , k . getValue ( ) ) ; if ( nameMatches && valueMatches ) { return h ; } } return null ; } @ Override public Object parse ( String s ) throws Exception { List < Header > expected = new ArrayList < Header > ( ) ; if ( ! "<STR_LIT>" . equals ( s . trim ( ) ) ) { String expStr = Tools . fromHtml ( s . trim ( ) ) ; String [ ] nvpArray = expStr . split ( "<STR_LIT:n>" ) ; for ( String nvp : nvpArray ) { try { String [ ] nvpEl = nvp . split ( "<STR_LIT::>" , <NUM_LIT:2> ) ; expected . add ( new Header ( nvpEl [ <NUM_LIT:0> ] . trim ( ) , nvpEl [ <NUM_LIT:1> ] . trim ( ) ) ) ; } catch ( RuntimeException e ) { throw new IllegalArgumentException ( "<STR_LIT>" ) ; } } } return expected ; } @ Override @ SuppressWarnings ( "<STR_LIT:unchecked>" ) public String toString ( Object obj ) { StringBuffer b = new StringBuffer ( ) ; List < Header > list = ( List < Header > ) obj ; for ( Header h : list ) { b . append ( h . getName ( ) ) . append ( "<STR_LIT:U+0020:U+0020>" ) . append ( h . getValue ( ) ) . append ( "<STR_LIT:n>" ) ; } return b . toString ( ) . trim ( ) ; } } </s> |
<s> package smartrics . rest . fitnesse . fixture . support ; import java . nio . charset . Charset ; import java . util . HashMap ; import java . util . Map ; public class BodyTypeAdapterFactory { @ SuppressWarnings ( "<STR_LIT:rawtypes>" ) private static Map < ContentType , Class > contentTypeToBodyTypeAdapter = new HashMap < ContentType , Class > ( ) ; static { contentTypeToBodyTypeAdapter . put ( ContentType . JS , JSONBodyTypeAdapter . class ) ; contentTypeToBodyTypeAdapter . put ( ContentType . JSON , JSONBodyTypeAdapter . class ) ; contentTypeToBodyTypeAdapter . put ( ContentType . XML , XPathBodyTypeAdapter . class ) ; contentTypeToBodyTypeAdapter . put ( ContentType . TEXT , TextBodyTypeAdapter . class ) ; } private BodyTypeAdapterFactory ( ) { } public static BodyTypeAdapter getBodyTypeAdapter ( ContentType content , String charset ) { @ SuppressWarnings ( "<STR_LIT:rawtypes>" ) Class aClass = contentTypeToBodyTypeAdapter . get ( content ) ; if ( aClass == null ) { throw new IllegalArgumentException ( "<STR_LIT>" ) ; } BodyTypeAdapter instance = null ; try { instance = ( BodyTypeAdapter ) aClass . newInstance ( ) ; if ( charset != null ) { instance . setCharset ( charset ) ; } else { instance . setCharset ( Charset . defaultCharset ( ) . name ( ) ) ; } } catch ( InstantiationException e ) { throw new IllegalStateException ( "<STR_LIT>" + content + "<STR_LIT:(>" + aClass . getName ( ) + "<STR_LIT:)>" ) ; } catch ( IllegalAccessException e ) { throw new IllegalStateException ( "<STR_LIT>" + content + "<STR_LIT:(>" + aClass . getName ( ) + "<STR_LIT:)>" ) ; } return instance ; } } </s> |
<s> package smartrics . rest . fitnesse . fixture . support ; public class StringTypeAdapter extends RestDataTypeAdapter { public StringTypeAdapter ( ) { } @ Override public boolean equals ( Object expected , Object actual ) { String se = "<STR_LIT:null>" ; if ( expected != null ) { se = expected . toString ( ) ; } String sa = "<STR_LIT:null>" ; if ( actual != null ) { sa = actual . toString ( ) ; } return se . equals ( sa ) ; } @ Override public Object parse ( String s ) { if ( "<STR_LIT:null>" . equals ( s ) ) { return null ; } if ( "<STR_LIT>" . equals ( s ) ) { return "<STR_LIT>" ; } return s ; } @ Override public String toString ( Object obj ) { if ( obj == null ) { return "<STR_LIT:null>" ; } if ( "<STR_LIT>" . equals ( obj . toString ( ) . trim ( ) ) ) { return "<STR_LIT>" ; } return obj . toString ( ) ; } } </s> |
<s> package smartrics . rest . fitnesse . fixture . support ; import org . apache . commons . httpclient . Credentials ; import org . apache . commons . httpclient . HostConfiguration ; import org . apache . commons . httpclient . HttpClient ; import org . apache . commons . httpclient . UsernamePasswordCredentials ; import org . apache . commons . httpclient . auth . AuthScope ; import org . apache . commons . httpclient . params . HostParams ; import org . apache . commons . httpclient . params . HttpClientParams ; public class HttpClientBuilder { public static final Integer DEFAULT_SO_TO = <NUM_LIT> ; public static final Integer DEFAULT_PROXY_PORT = <NUM_LIT> ; public HttpClient createHttpClient ( final Config config ) { HttpClient client = createConfiguredClient ( config ) ; if ( config != null ) { configureHost ( config , client ) ; configureCredentials ( config , client ) ; } return client ; } private HttpClient createConfiguredClient ( final Config config ) { HttpClientParams params = new HttpClientParams ( ) ; params . setSoTimeout ( DEFAULT_SO_TO ) ; if ( config != null ) { params . setSoTimeout ( config . getAsInteger ( "<STR_LIT>" , DEFAULT_SO_TO ) ) ; } HttpClient client = new HttpClient ( params ) ; return client ; } private void configureHost ( final Config config , HttpClient client ) { HostConfiguration hostConfiguration = client . getHostConfiguration ( ) ; String proxyHost = config . get ( "<STR_LIT>" ) ; if ( proxyHost != null ) { int proxyPort = config . getAsInteger ( "<STR_LIT>" , DEFAULT_PROXY_PORT ) ; hostConfiguration . setProxy ( proxyHost , proxyPort ) ; } HostParams hostParams = new HostParams ( ) ; hostConfiguration . setParams ( hostParams ) ; } private void configureCredentials ( final Config config , HttpClient client ) { String username = config . get ( "<STR_LIT>" ) ; String password = config . get ( "<STR_LIT>" ) ; if ( username != null && password != null ) { Credentials defaultcreds = new UsernamePasswordCredentials ( username , password ) ; client . getState ( ) . setCredentials ( AuthScope . ANY , defaultcreds ) ; } } } </s> |
<s> package smartrics . rest . fitnesse . fixture . support ; public class JavascriptException extends RuntimeException { private static final long serialVersionUID = <NUM_LIT:1L> ; public JavascriptException ( String message ) { super ( message ) ; } } </s> |
<s> package smartrics . rest . fitnesse . fixture . support ; import java . lang . reflect . InvocationTargetException ; import java . util . ArrayList ; import java . util . HashMap ; import java . util . List ; import java . util . Map ; import org . mozilla . javascript . Context ; import org . mozilla . javascript . EcmaError ; import org . mozilla . javascript . EvaluatorException ; import org . mozilla . javascript . Scriptable ; import org . mozilla . javascript . ScriptableObject ; import smartrics . rest . client . RestData . Header ; import smartrics . rest . client . RestResponse ; public class JavascriptWrapper { private static final String RESPONSE_OBJ_NAME = "<STR_LIT>" ; private static final String SYMBOLS_OBJ_NAME = "<STR_LIT>" ; private static final String JSON_OBJ_NAME = "<STR_LIT>" ; public Object evaluateExpression ( RestResponse response , String expression ) { if ( expression == null ) { return null ; } Context context = Context . enter ( ) ; ScriptableObject scope = context . initStandardObjects ( ) ; injectFitNesseSymbolMap ( scope ) ; injectResponse ( context , scope , response ) ; Object result = evaluateExpression ( context , scope , expression ) ; return result ; } public Object evaluateExpression ( String json , String expression ) { if ( json == null || expression == null ) { return null ; } Context context = Context . enter ( ) ; ScriptableObject scope = context . initStandardObjects ( ) ; injectFitNesseSymbolMap ( scope ) ; injectJson ( context , scope , json ) ; Object result = evaluateExpression ( context , scope , expression ) ; return result ; } public boolean looksLikeAJsExpression ( String json ) { return json != null && json . contains ( JSON_OBJ_NAME + "<STR_LIT:.>" ) ; } private void injectFitNesseSymbolMap ( ScriptableObject scope ) { Variables v = new Variables ( ) ; Object wrappedVariables = Context . javaToJS ( v , scope ) ; ScriptableObject . putProperty ( scope , SYMBOLS_OBJ_NAME , wrappedVariables ) ; } private void injectJson ( Context cx , ScriptableObject scope , String json ) { evaluateExpression ( cx , scope , "<STR_LIT>" + JSON_OBJ_NAME + "<STR_LIT:=>" + json ) ; } private Object evaluateExpression ( Context context , ScriptableObject scope , String expression ) { try { Object result = context . evaluateString ( scope , expression , null , <NUM_LIT:1> , null ) ; return result ; } catch ( EvaluatorException e ) { throw new JavascriptException ( e . getMessage ( ) ) ; } catch ( EcmaError e ) { throw new JavascriptException ( e . getMessage ( ) ) ; } } private void injectResponse ( Context cx , ScriptableObject scope , RestResponse r ) { try { ScriptableObject . defineClass ( scope , JsResponse . class ) ; Scriptable response = null ; if ( r == null ) { scope . put ( RESPONSE_OBJ_NAME , scope , response ) ; return ; } Object [ ] arg = new Object [ <NUM_LIT:1> ] ; arg [ <NUM_LIT:0> ] = r ; response = cx . newObject ( scope , "<STR_LIT>" , arg ) ; scope . put ( RESPONSE_OBJ_NAME , scope , response ) ; putPropertyOnJsObject ( response , "<STR_LIT:body>" , r . getBody ( ) ) ; putPropertyOnJsObject ( response , JSON_OBJ_NAME , null ) ; boolean isJson = isJsonResponse ( r ) ; if ( isJson ) { evaluateExpression ( cx , scope , RESPONSE_OBJ_NAME + "<STR_LIT:.>" + JSON_OBJ_NAME + "<STR_LIT:=>" + r . getBody ( ) ) ; } putPropertyOnJsObject ( response , "<STR_LIT>" , r . getResource ( ) ) ; putPropertyOnJsObject ( response , "<STR_LIT>" , r . getStatusText ( ) ) ; putPropertyOnJsObject ( response , "<STR_LIT>" , r . getStatusCode ( ) ) ; putPropertyOnJsObject ( response , "<STR_LIT>" , r . getTransactionId ( ) ) ; for ( Header h : r . getHeaders ( ) ) { callMethodOnJsObject ( response , "<STR_LIT>" , h . getName ( ) , h . getValue ( ) ) ; } } catch ( IllegalAccessException e ) { throw new JavascriptException ( e . getMessage ( ) ) ; } catch ( InstantiationException e ) { throw new JavascriptException ( e . getMessage ( ) ) ; } catch ( InvocationTargetException e ) { throw new JavascriptException ( e . getMessage ( ) ) ; } } private void callMethodOnJsObject ( Scriptable o , String mName , Object ... arg ) { ScriptableObject . callMethod ( o , mName , arg ) ; } private void putPropertyOnJsObject ( Scriptable o , String mName , Object value ) { ScriptableObject . putProperty ( o , mName , value ) ; } private boolean isJsonResponse ( RestResponse r ) { if ( ContentType . JSON . equals ( ContentType . parse ( r . getHeader ( "<STR_LIT:Content-Type>" ) ) ) ) { return true ; } if ( r . getBody ( ) != null && r . getBody ( ) . trim ( ) . matches ( "<STR_LIT>" ) ) { return Tools . isValidJson ( r . getBody ( ) ) ; } return false ; } public static class JsResponse extends ScriptableObject { private static final long serialVersionUID = <NUM_LIT> ; private Map < String , List < String > > headers ; public JsResponse ( ) { } public void jsConstructor ( ) { headers = new HashMap < String , List < String > > ( ) ; } @ Override public String getClassName ( ) { return "<STR_LIT>" ; } public void jsFunction_addHeader ( String name , String value ) { List < String > vals = headers . get ( name ) ; if ( vals == null ) { vals = new ArrayList < String > ( ) ; headers . put ( name , vals ) ; } vals . add ( value ) ; } public void jsFunction_putHeader ( String name , String value ) { List < String > vals = new ArrayList < String > ( ) ; vals . add ( value ) ; headers . put ( name , vals ) ; } public int jsFunction_headerListSize ( String name ) { List < String > vals = headers . get ( name ) ; if ( vals == null || vals . size ( ) == <NUM_LIT:0> ) { return <NUM_LIT:0> ; } return vals . size ( ) ; } public int jsFunction_headersSize ( ) { int sz = <NUM_LIT:0> ; for ( List < String > hList : headers . values ( ) ) { sz += hList . size ( ) ; } return sz ; } public String jsFunction_header0 ( String name ) { return jsFunction_header ( name , <NUM_LIT:0> ) ; } public List < String > jsFunction_headers ( String name ) { int sz = jsFunction_headerListSize ( name ) ; if ( sz > <NUM_LIT:0> ) { return headers . get ( name ) ; } else { return new ArrayList < String > ( ) ; } } public String jsFunction_header ( String name , int pos ) { if ( jsFunction_headerListSize ( name ) > <NUM_LIT:0> ) { return headers . get ( name ) . get ( pos ) ; } else { return null ; } } } } </s> |
<s> package smartrics . rest . fitnesse . fixture . support ; import java . io . BufferedReader ; import java . io . ByteArrayInputStream ; import java . io . IOException ; import java . io . InputStream ; import java . io . InputStreamReader ; import java . io . StringReader ; import java . io . StringWriter ; import java . io . UnsupportedEncodingException ; import java . nio . charset . Charset ; import java . util . HashMap ; import java . util . Iterator ; import java . util . List ; import java . util . Map ; import java . util . Map . Entry ; import java . util . Random ; import java . util . regex . Pattern ; import java . util . regex . PatternSyntaxException ; import javax . xml . XMLConstants ; import javax . xml . namespace . NamespaceContext ; import javax . xml . namespace . QName ; import javax . xml . parsers . DocumentBuilder ; import javax . xml . parsers . DocumentBuilderFactory ; import javax . xml . parsers . ParserConfigurationException ; import javax . xml . transform . OutputKeys ; import javax . xml . transform . Transformer ; import javax . xml . transform . TransformerFactory ; import javax . xml . transform . dom . DOMSource ; import javax . xml . transform . stream . StreamResult ; import javax . xml . xpath . XPath ; import javax . xml . xpath . XPathConstants ; import javax . xml . xpath . XPathExpression ; import javax . xml . xpath . XPathExpressionException ; import javax . xml . xpath . XPathFactory ; import org . json . JSONException ; import org . json . JSONObject ; import org . w3c . dom . Document ; import org . w3c . dom . Node ; import org . w3c . dom . NodeList ; import org . xml . sax . SAXException ; import com . thoughtworks . xstream . io . HierarchicalStreamDriver ; import com . thoughtworks . xstream . io . HierarchicalStreamReader ; import com . thoughtworks . xstream . io . copy . HierarchicalStreamCopier ; import com . thoughtworks . xstream . io . json . JettisonMappedXmlDriver ; import com . thoughtworks . xstream . io . xml . PrettyPrintWriter ; public final class Tools { private Tools ( ) { } public static NodeList extractXPath ( Map < String , String > ns , String xpathExpression , String content ) { return ( NodeList ) extractXPath ( ns , xpathExpression , content , XPathConstants . NODESET , null ) ; } public static NodeList extractXPath ( Map < String , String > ns , String xpathExpression , String content , String encoding ) { return ( NodeList ) extractXPath ( ns , xpathExpression , content , XPathConstants . NODESET , encoding ) ; } public static Object extractXPath ( String xpathExpression , String content , QName returnType ) { return extractXPath ( xpathExpression , content , returnType , null ) ; } public static Object extractXPath ( String xpathExpression , String content , QName returnType , String encoding ) { return extractXPath ( new HashMap < String , String > ( ) , xpathExpression , content , returnType , encoding ) ; } public static Object extractXPath ( Map < String , String > ns , String xpathExpression , String content , QName returnType ) { return extractXPath ( ns , xpathExpression , content , returnType , null ) ; } public static Object extractXPath ( Map < String , String > ns , String xpathExpression , String content , QName returnType , String charset ) { if ( null == ns ) { ns = new HashMap < String , String > ( ) ; } String ch = charset ; if ( ch == null ) { ch = Charset . defaultCharset ( ) . name ( ) ; } Document doc = toDocument ( content , charset ) ; XPathExpression expr = toExpression ( ns , xpathExpression ) ; try { Object o = expr . evaluate ( doc , returnType ) ; return o ; } catch ( XPathExpressionException e ) { throw new IllegalArgumentException ( "<STR_LIT>" + xpathExpression ) ; } } public static String xPathResultToXmlString ( Object result ) { if ( result == null ) { return null ; } try { StringWriter sw = new StringWriter ( ) ; Transformer serializer = TransformerFactory . newInstance ( ) . newTransformer ( ) ; serializer . setOutputProperty ( OutputKeys . INDENT , "<STR_LIT:yes>" ) ; serializer . setOutputProperty ( OutputKeys . MEDIA_TYPE , "<STR_LIT>" ) ; if ( result instanceof NodeList ) { serializer . transform ( new DOMSource ( ( ( NodeList ) result ) . item ( <NUM_LIT:0> ) ) , new StreamResult ( sw ) ) ; } else if ( result instanceof Node ) { serializer . transform ( new DOMSource ( ( Node ) result ) , new StreamResult ( sw ) ) ; } else { return result . toString ( ) ; } return sw . toString ( ) ; } catch ( Exception e ) { throw new RuntimeException ( "<STR_LIT>" , e ) ; } } public static boolean isValidXPath ( Map < String , String > ns , String xpathExpression ) { try { toExpression ( ns , xpathExpression ) ; return true ; } catch ( IllegalArgumentException e ) { return false ; } } public static XPathExpression toExpression ( Map < String , String > ns , String xpathExpression ) { try { XPathFactory xpathFactory = XPathFactory . newInstance ( ) ; XPath xpath = xpathFactory . newXPath ( ) ; if ( ns . size ( ) > <NUM_LIT:0> ) { xpath . setNamespaceContext ( toNsContext ( ns ) ) ; } XPathExpression expr = xpath . compile ( xpathExpression ) ; return expr ; } catch ( XPathExpressionException e ) { throw new IllegalArgumentException ( "<STR_LIT>" + xpathExpression , e ) ; } } private static NamespaceContext toNsContext ( final Map < String , String > ns ) { NamespaceContext ctx = new NamespaceContext ( ) { @ Override public String getNamespaceURI ( String prefix ) { String u = ns . get ( prefix ) ; if ( null == u ) { return XMLConstants . NULL_NS_URI ; } return u ; } @ Override public String getPrefix ( String namespaceURI ) { for ( String k : ns . keySet ( ) ) { if ( ns . get ( k ) . equals ( namespaceURI ) ) { return k ; } } return null ; } @ Override public Iterator < ? > getPrefixes ( String namespaceURI ) { return null ; } } ; return ctx ; } private static Document toDocument ( String content , String charset ) { String ch = charset ; if ( ch == null ) { ch = Charset . defaultCharset ( ) . name ( ) ; } DocumentBuilderFactory factory = DocumentBuilderFactory . newInstance ( ) ; factory . setNamespaceAware ( true ) ; try { DocumentBuilder builder = factory . newDocumentBuilder ( ) ; Document doc = builder . parse ( getInputStreamFromString ( content , ch ) ) ; return doc ; } catch ( ParserConfigurationException e ) { throw new IllegalArgumentException ( "<STR_LIT>" , e ) ; } catch ( SAXException e ) { throw new IllegalArgumentException ( "<STR_LIT>" , e ) ; } catch ( IOException e ) { throw new IllegalArgumentException ( "<STR_LIT>" , e ) ; } } public static boolean isValidJson ( String presumeblyJson ) { Object o = null ; try { o = new JSONObject ( presumeblyJson ) ; } catch ( JSONException e ) { return false ; } return o != null ; } public static String fromJSONtoXML ( String json ) { HierarchicalStreamDriver driver = new JettisonMappedXmlDriver ( ) ; StringReader reader = new StringReader ( json ) ; HierarchicalStreamReader hsr = driver . createReader ( reader ) ; StringWriter writer = new StringWriter ( ) ; try { new HierarchicalStreamCopier ( ) . copy ( hsr , new PrettyPrintWriter ( writer ) ) ; return writer . toString ( ) ; } finally { if ( writer != null ) { try { writer . close ( ) ; } catch ( IOException e ) { } } } } public static String getStringFromInputStream ( InputStream is ) { return getStringFromInputStream ( is , Charset . defaultCharset ( ) . name ( ) ) ; } public static String getStringFromInputStream ( InputStream is , String encoding ) { String line = null ; if ( is == null ) { return "<STR_LIT>" ; } BufferedReader in = null ; try { in = new BufferedReader ( new InputStreamReader ( is , encoding ) ) ; } catch ( UnsupportedEncodingException e ) { throw new IllegalArgumentException ( "<STR_LIT>" + encoding , e ) ; } StringBuilder sb = new StringBuilder ( ) ; try { while ( ( line = in . readLine ( ) ) != null ) { sb . append ( line ) ; } } catch ( IOException e ) { throw new IllegalArgumentException ( "<STR_LIT>" , e ) ; } return sb . toString ( ) ; } public static InputStream getInputStreamFromString ( String string , String charset ) { if ( string == null ) { throw new IllegalArgumentException ( "<STR_LIT>" ) ; } try { byte [ ] byteArray = string . getBytes ( charset ) ; return new ByteArrayInputStream ( byteArray ) ; } catch ( UnsupportedEncodingException e ) { throw new IllegalArgumentException ( "<STR_LIT>" + charset ) ; } } public static String convertMapToString ( Map < String , String > map , String nvSep , String entrySep ) { StringBuffer sb = new StringBuffer ( ) ; if ( map != null ) { for ( Entry < String , String > entry : map . entrySet ( ) ) { String el = entry . getKey ( ) ; sb . append ( convertEntryToString ( el , map . get ( el ) , nvSep ) ) . append ( entrySep ) ; } } String repr = sb . toString ( ) ; int pos = repr . lastIndexOf ( entrySep ) ; return repr . substring ( <NUM_LIT:0> , pos ) ; } public static String convertEntryToString ( String name , String value , String nvSep ) { return String . format ( "<STR_LIT>" , name , nvSep , value ) ; } public static boolean regex ( String text , String expr ) { try { Pattern p = Pattern . compile ( expr ) ; boolean find = p . matcher ( text ) . find ( ) ; return find ; } catch ( PatternSyntaxException e ) { throw new IllegalArgumentException ( "<STR_LIT>" + expr ) ; } } public static Map < String , String > convertStringToMap ( final String expStr , final String nvSep , final String entrySep , boolean cleanTags ) { String sanitisedExpStr = expStr . trim ( ) ; sanitisedExpStr = removeOpenEscape ( sanitisedExpStr ) ; sanitisedExpStr = removeCloseEscape ( sanitisedExpStr ) ; sanitisedExpStr = sanitisedExpStr . trim ( ) ; String [ ] nvpArray = sanitisedExpStr . split ( entrySep ) ; Map < String , String > ret = new HashMap < String , String > ( ) ; for ( String nvp : nvpArray ) { try { nvp = nvp . trim ( ) ; if ( "<STR_LIT>" . equals ( nvp ) ) { continue ; } nvp = removeOpenEscape ( nvp ) . trim ( ) ; nvp = removeCloseEscape ( nvp ) . trim ( ) ; String [ ] nvpArr = nvp . split ( nvSep ) ; String k , v ; k = nvpArr [ <NUM_LIT:0> ] . trim ( ) ; v = "<STR_LIT>" ; if ( nvpArr . length == <NUM_LIT:2> ) { v = nvpArr [ <NUM_LIT:1> ] . trim ( ) ; } else if ( nvpArr . length > <NUM_LIT:2> ) { int pos = nvp . indexOf ( nvSep ) + nvSep . length ( ) ; v = nvp . substring ( pos ) . trim ( ) ; } if ( cleanTags ) { ret . put ( k , fromSimpleTag ( v ) ) ; } else { ret . put ( k , v ) ; } } catch ( RuntimeException e ) { throw new IllegalArgumentException ( "<STR_LIT>" + entrySep + "<STR_LIT>" + nvSep + "<STR_LIT:value>" ) ; } } return ret ; } public static String makeToggleCollapseable ( String message , String content ) { Random random = new Random ( ) ; String id = Integer . toString ( content . hashCode ( ) ) + Long . toString ( random . nextLong ( ) ) ; StringBuffer sb = new StringBuffer ( ) ; sb . append ( "<STR_LIT>" + id + "<STR_LIT>" ) ; sb . append ( "<STR_LIT>" + id + "<STR_LIT>" + message + "<STR_LIT>" ) ; sb . append ( "<STR_LIT>" + id + "<STR_LIT>" ) . append ( content ) . append ( "<STR_LIT>" ) ; return sb . toString ( ) ; } public static String toHtml ( String text ) { return text . replaceAll ( "<STR_LIT>" , "<STR_LIT>" ) . replaceAll ( "<STR_LIT>" , "<STR_LIT>" ) . replaceAll ( "<STR_LIT:<>" , "<STR_LIT>" ) . replaceAll ( "<STR_LIT:>>" , "<STR_LIT>" ) . replaceAll ( "<STR_LIT:n>" , "<STR_LIT>" ) . replaceAll ( "<STR_LIT:t>" , "<STR_LIT:U+0020U+0020U+0020U+0020>" ) . replaceAll ( "<STR_LIT:U+0020>" , "<STR_LIT>" ) . replaceAll ( "<STR_LIT>" , "<STR_LIT>" ) ; } public static String toCode ( String c ) { return "<STR_LIT>" + c + "<STR_LIT>" ; } public static String fromSimpleTag ( String somethingWithinATag ) { return somethingWithinATag . replaceAll ( "<STR_LIT>" , "<STR_LIT>" ) . replace ( "<STR_LIT>" , "<STR_LIT>" ) ; } public static String fromHtml ( String text ) { String ls = "<STR_LIT:n>" ; return text . replaceAll ( "<STR_LIT>" , ls ) . replaceAll ( "<STR_LIT>" , ls ) . replaceAll ( "<STR_LIT>" , "<STR_LIT>" ) . replaceAll ( "<STR_LIT>" , "<STR_LIT>" ) . replaceAll ( "<STR_LIT>" , "<STR_LIT>" ) . replaceAll ( "<STR_LIT>" , "<STR_LIT>" ) . replaceAll ( "<STR_LIT>" , "<STR_LIT:U+0020>" ) . replaceAll ( "<STR_LIT>" , "<STR_LIT:>>" ) . replaceAll ( "<STR_LIT>" , "<STR_LIT:<>" ) . replaceAll ( "<STR_LIT>" , "<STR_LIT:U+0020>" ) ; } public static String toHtmlLabel ( String string ) { return "<STR_LIT>" + string + "<STR_LIT>" ; } public static String toHtmlLink ( String href , String text ) { return "<STR_LIT>" + href + "<STR_LIT>" + text + "<STR_LIT>" ; } public static String makeContentForWrongCell ( String expected , RestDataTypeAdapter typeAdapter , CellFormatter < ? > formatter , int minLenForToggle ) { StringBuffer sb = new StringBuffer ( ) ; sb . append ( Tools . toHtml ( expected ) ) ; if ( formatter . isDisplayActual ( ) ) { sb . append ( toHtml ( "<STR_LIT:n>" ) ) ; sb . append ( formatter . label ( "<STR_LIT>" ) ) ; String actual = typeAdapter . toString ( ) ; sb . append ( toHtml ( "<STR_LIT>" ) ) ; sb . append ( toHtml ( "<STR_LIT:n>" ) ) ; if ( minLenForToggle >= <NUM_LIT:0> && actual . length ( ) > minLenForToggle ) { sb . append ( makeToggleCollapseable ( "<STR_LIT>" , toHtml ( actual ) ) ) ; } else { sb . append ( toHtml ( actual ) ) ; } sb . append ( toHtml ( "<STR_LIT:n>" ) ) ; sb . append ( formatter . label ( "<STR_LIT>" ) ) ; } List < String > errors = typeAdapter . getErrors ( ) ; if ( errors . size ( ) > <NUM_LIT:0> ) { sb . append ( toHtml ( "<STR_LIT>" ) ) ; sb . append ( toHtml ( "<STR_LIT:n>" ) ) ; for ( String e : errors ) { sb . append ( toHtml ( e + "<STR_LIT:n>" ) ) ; } sb . append ( toHtml ( "<STR_LIT:n>" ) ) ; sb . append ( formatter . label ( "<STR_LIT>" ) ) ; } return sb . toString ( ) ; } public static String makeContentForRightCell ( String expected , RestDataTypeAdapter typeAdapter , CellFormatter < ? > formatter , int minLenForToggle ) { StringBuffer sb = new StringBuffer ( ) ; sb . append ( toHtml ( expected ) ) ; String actual = typeAdapter . toString ( ) ; if ( formatter . isDisplayActual ( ) && ! expected . equals ( actual ) ) { sb . append ( toHtml ( "<STR_LIT:n>" ) ) ; sb . append ( formatter . label ( "<STR_LIT>" ) ) ; sb . append ( toHtml ( "<STR_LIT>" ) ) ; sb . append ( toHtml ( "<STR_LIT:n>" ) ) ; if ( minLenForToggle >= <NUM_LIT:0> && actual . length ( ) > minLenForToggle ) { sb . append ( makeToggleCollapseable ( "<STR_LIT>" , toHtml ( actual ) ) ) ; } else { sb . append ( toHtml ( actual ) ) ; } sb . append ( toHtml ( "<STR_LIT:n>" ) ) ; sb . append ( formatter . label ( "<STR_LIT>" ) ) ; } return sb . toString ( ) ; } private static String removeCloseEscape ( String str ) { return trimStartEnd ( "<STR_LIT>" , str ) ; } private static String removeOpenEscape ( String str ) { return trimStartEnd ( "<STR_LIT>" , str ) ; } private static String trimStartEnd ( String pattern , String str ) { if ( str . startsWith ( pattern ) ) { str = str . substring ( <NUM_LIT:2> ) ; } if ( str . endsWith ( pattern ) ) { str = str . substring ( <NUM_LIT:0> , str . length ( ) - <NUM_LIT:2> ) ; } return str ; } } </s> |
<s> package smartrics . rest . fitnesse . fixture . support . http ; import org . apache . commons . httpclient . HostConfiguration ; import org . apache . commons . httpclient . URI ; import org . apache . commons . httpclient . URIException ; public class PostMethod extends org . apache . commons . httpclient . methods . PostMethod { @ SuppressWarnings ( "<STR_LIT:deprecation>" ) public URI getURI ( ) throws URIException { HostConfiguration conf = super . getHostConfiguration ( ) ; String scheme = conf . getProtocol ( ) . getScheme ( ) ; String host = conf . getHost ( ) ; int port = conf . getPort ( ) ; return new URIBuilder ( ) . getURI ( scheme , host , port , getPath ( ) , getQueryString ( ) , getParams ( ) ) ; } public void setURI ( URI uri ) throws URIException { new URIBuilder ( ) . setURI ( this , uri ) ; } } </s> |
<s> package smartrics . rest . fitnesse . fixture . support . http ; import org . apache . commons . httpclient . HostConfiguration ; import org . apache . commons . httpclient . HttpHost ; import org . apache . commons . httpclient . HttpURL ; import org . apache . commons . httpclient . URI ; import org . apache . commons . httpclient . URIException ; import org . apache . commons . httpclient . params . HttpMethodParams ; class URIBuilder { public URI getURI ( String scheme , String host , int port , String path , String queryString , HttpMethodParams params ) throws URIException { HttpHost httphost = new HttpHost ( host , port ) ; StringBuffer buffer = new StringBuffer ( ) ; if ( httphost != null ) { buffer . append ( httphost . getProtocol ( ) . getScheme ( ) ) ; buffer . append ( "<STR_LIT>" ) ; buffer . append ( httphost . getHostName ( ) ) ; int p = httphost . getPort ( ) ; if ( p != - <NUM_LIT:1> && p != httphost . getProtocol ( ) . getDefaultPort ( ) ) { buffer . append ( "<STR_LIT::>" ) ; buffer . append ( p ) ; } } buffer . append ( path ) ; if ( queryString != null ) { buffer . append ( '<CHAR_LIT>' ) ; buffer . append ( queryString ) ; } String charset = params . getUriCharset ( ) ; return new HttpURL ( buffer . toString ( ) , charset ) ; } @ SuppressWarnings ( "<STR_LIT:deprecation>" ) public void setURI ( org . apache . commons . httpclient . HttpMethodBase m , URI uri ) throws URIException { HostConfiguration conf = m . getHostConfiguration ( ) ; if ( uri . isAbsoluteURI ( ) ) { conf . setHost ( new HttpHost ( uri ) ) ; m . setHostConfiguration ( conf ) ; } m . setPath ( uri . getPath ( ) != null ? uri . getEscapedPath ( ) : "<STR_LIT:/>" ) ; m . setQueryString ( uri . getQuery ( ) ) ; } } </s> |
<s> package smartrics . rest . fitnesse . fixture . support . http ; import org . apache . commons . httpclient . HostConfiguration ; import org . apache . commons . httpclient . URI ; import org . apache . commons . httpclient . URIException ; public class GetMethod extends org . apache . commons . httpclient . methods . GetMethod { @ SuppressWarnings ( "<STR_LIT:deprecation>" ) public URI getURI ( ) throws URIException { HostConfiguration conf = super . getHostConfiguration ( ) ; String scheme = conf . getProtocol ( ) . getScheme ( ) ; String host = conf . getHost ( ) ; int port = conf . getPort ( ) ; return new URIBuilder ( ) . getURI ( scheme , host , port , getPath ( ) , getQueryString ( ) , getParams ( ) ) ; } public void setURI ( URI uri ) throws URIException { new URIBuilder ( ) . setURI ( this , uri ) ; } } </s> |
<s> package smartrics . rest . fitnesse . fixture . support . http ; import org . apache . commons . httpclient . HostConfiguration ; import org . apache . commons . httpclient . URI ; import org . apache . commons . httpclient . URIException ; public class DeleteMethod extends org . apache . commons . httpclient . methods . DeleteMethod { @ SuppressWarnings ( "<STR_LIT:deprecation>" ) public URI getURI ( ) throws URIException { HostConfiguration conf = super . getHostConfiguration ( ) ; String scheme = conf . getProtocol ( ) . getScheme ( ) ; String host = conf . getHost ( ) ; int port = conf . getPort ( ) ; return new URIBuilder ( ) . getURI ( scheme , host , port , getPath ( ) , getQueryString ( ) , getParams ( ) ) ; } public void setURI ( URI uri ) throws URIException { new URIBuilder ( ) . setURI ( this , uri ) ; } } </s> |
<s> package smartrics . rest . fitnesse . fixture . support . http ; import org . apache . commons . httpclient . HostConfiguration ; import org . apache . commons . httpclient . URI ; import org . apache . commons . httpclient . URIException ; public class PutMethod extends org . apache . commons . httpclient . methods . PutMethod { @ SuppressWarnings ( "<STR_LIT:deprecation>" ) public URI getURI ( ) throws URIException { HostConfiguration conf = super . getHostConfiguration ( ) ; String scheme = conf . getProtocol ( ) . getScheme ( ) ; String host = conf . getHost ( ) ; int port = conf . getPort ( ) ; return new URIBuilder ( ) . getURI ( scheme , host , port , getPath ( ) , getQueryString ( ) , getParams ( ) ) ; } public void setURI ( URI uri ) throws URIException { new URIBuilder ( ) . setURI ( this , uri ) ; } } </s> |
<s> package smartrics . rest . fitnesse . fixture . support ; import java . util . ArrayList ; import java . util . Collections ; import java . util . List ; import java . util . Map ; import fit . TypeAdapter ; public abstract class RestDataTypeAdapter extends TypeAdapter implements fitnesse . slim . Converter { private final List < String > errors = new ArrayList < String > ( ) ; private Object actual ; private Map < String , String > context ; @ Override public String toString ( ) { return toString ( get ( ) ) ; } @ Override public void set ( Object a ) { this . actual = a ; } @ Override public Object get ( ) { return actual ; } protected void addError ( String e ) { errors . add ( e ) ; } public List < String > getErrors ( ) { return Collections . unmodifiableList ( errors ) ; } public void setContext ( Map < String , String > c ) { this . context = c ; } protected Map < String , String > getContext ( ) { return context ; } public Object fromString ( String o ) { try { return this . parse ( o ) ; } catch ( Exception e ) { throw new RuntimeException ( "<STR_LIT>" + this . getClass ( ) . getName ( ) + "<STR_LIT::U+0020>" + o ) ; } } } </s> |
<s> package smartrics . rest . fitnesse . fixture . support ; import java . util . HashMap ; import java . util . Map ; public class LetHandlerFactory { private static Map < String , LetHandler > strategies = new HashMap < String , LetHandler > ( ) ; static { strategies . put ( "<STR_LIT>" , new LetHeaderHandler ( ) ) ; strategies . put ( "<STR_LIT:body>" , new LetBodyHandler ( ) ) ; strategies . put ( "<STR_LIT>" , new LetBodyXmlHandler ( ) ) ; strategies . put ( "<STR_LIT>" , new LetBodyJsHandler ( ) ) ; } private LetHandlerFactory ( ) { } public static LetHandler getHandlerFor ( String part ) { return strategies . get ( part ) ; } } </s> |
<s> package smartrics . rest . fitnesse . fixture . support ; import java . util . HashMap ; import java . util . Map ; public final class Config { public static final String DEFAULT_CONFIG_NAME = "<STR_LIT:default>" ; private static final Map < String , Config > CONFIGURATIONS = new HashMap < String , Config > ( ) ; public static Config getConfig ( ) { return getConfig ( DEFAULT_CONFIG_NAME ) ; } public static Config getConfig ( String name ) { if ( name == null ) { name = DEFAULT_CONFIG_NAME ; } Config namedConfig = CONFIGURATIONS . get ( name ) ; if ( namedConfig == null ) { namedConfig = new Config ( name ) ; CONFIGURATIONS . put ( name , namedConfig ) ; } return namedConfig ; } private final String name ; private Map < String , String > data ; private Config ( final String name ) { this . name = name ; this . data = new HashMap < String , String > ( ) ; } public String getName ( ) { return name ; } public void add ( String key , String value ) { data . put ( key , value ) ; } public String get ( String key ) { return data . get ( key ) ; } public String get ( String key , String def ) { String v = get ( key ) ; if ( v == null ) { v = def ; } return v ; } public Long getAsLong ( String key , Long def ) { String val = get ( key ) ; try { return Long . parseLong ( val ) ; } catch ( NumberFormatException e ) { return def ; } } public Boolean getAsBoolean ( String key , Boolean def ) { String val = get ( key ) ; if ( val == null ) { return def ; } return Boolean . parseBoolean ( val ) ; } public Integer getAsInteger ( String key , Integer def ) { String val = get ( key ) ; try { return Integer . parseInt ( val ) ; } catch ( NumberFormatException e ) { return def ; } } public Map < String , String > getAsMap ( String key , Map < String , String > def ) { String val = get ( key ) ; try { return Tools . convertStringToMap ( val , "<STR_LIT:n>" , "<STR_LIT:=>" , true ) ; } catch ( RuntimeException e ) { return def ; } } public void clear ( ) { data . clear ( ) ; } @ Override public String toString ( ) { return "<STR_LIT>" + getName ( ) + "<STR_LIT>" + data . toString ( ) ; } } </s> |
<s> package smartrics . rest . fitnesse . fixture . support ; import java . util . ArrayList ; import java . util . List ; import javax . xml . xpath . XPathConstants ; import org . w3c . dom . NodeList ; public class XPathBodyTypeAdapter extends BodyTypeAdapter { public XPathBodyTypeAdapter ( ) { } @ Override @ SuppressWarnings ( "<STR_LIT:unchecked>" ) public boolean equals ( final Object expected , final Object actual ) { if ( checkNoBody ( expected ) ) { return checkNoBody ( actual ) ; } if ( checkNoBody ( actual ) ) { return checkNoBody ( expected ) ; } List < String > expressions = ( List < String > ) expected ; for ( String expr : expressions ) { try { boolean b = eval ( expr , actual . toString ( ) ) ; if ( ! b ) { addError ( "<STR_LIT>" + expr + "<STR_LIT:'>" ) ; } } catch ( Exception e ) { throw new IllegalArgumentException ( "<STR_LIT>" + expr + "<STR_LIT>" + actual . toString ( ) , e ) ; } } return getErrors ( ) . size ( ) == <NUM_LIT:0> ; } protected boolean eval ( String expr , String content ) { Boolean b ; try { NodeList ret = Tools . extractXPath ( getContext ( ) , expr , content , getCharset ( ) ) ; return ! ( ret == null || ret . getLength ( ) == <NUM_LIT:0> ) ; } catch ( IllegalArgumentException e ) { b = ( Boolean ) Tools . extractXPath ( getContext ( ) , expr , content , XPathConstants . BOOLEAN , getCharset ( ) ) ; } return b ; } @ Override public Object parse ( String expectedListOfXpathsAsString ) throws Exception { List < String > expectedXPathAsList = new ArrayList < String > ( ) ; if ( expectedListOfXpathsAsString == null ) { return expectedXPathAsList ; } String expStr = expectedListOfXpathsAsString . trim ( ) ; if ( "<STR_LIT>" . equals ( expStr . trim ( ) ) ) { return expectedXPathAsList ; } if ( "<STR_LIT>" . equals ( expectedListOfXpathsAsString . trim ( ) ) ) { return expectedXPathAsList ; } expStr = Tools . fromHtml ( expStr ) ; String [ ] nvpArray = expStr . split ( "<STR_LIT:n>" ) ; for ( String nvp : nvpArray ) { if ( ! "<STR_LIT>" . equals ( nvp . trim ( ) ) ) { expectedXPathAsList . add ( nvp . trim ( ) ) ; } } return expectedXPathAsList ; } @ Override public String toXmlString ( String content ) { return content ; } } </s> |
<s> package smartrics . rest . fitnesse . fixture . support ; import java . util . Map ; import org . w3c . dom . NodeList ; import smartrics . rest . client . RestResponse ; public class LetBodyXmlHandler implements LetHandler { @ Override public String handle ( RestResponse response , Object expressionContext , String expression ) { @ SuppressWarnings ( "<STR_LIT:unchecked>" ) Map < String , String > namespaceContext = ( Map < String , String > ) expressionContext ; NodeList list = Tools . extractXPath ( namespaceContext , expression , response . getBody ( ) ) ; String val = Tools . xPathResultToXmlString ( list ) ; int pos = val . indexOf ( "<STR_LIT>" ) ; if ( pos >= <NUM_LIT:0> ) { val = val . substring ( pos + <NUM_LIT:2> ) ; } return val ; } } </s> |
<s> package smartrics . rest . fitnesse . fixture . support ; public interface CellFormatter < E > { void exception ( CellWrapper < E > cellWrapper , Throwable exception ) ; void exception ( CellWrapper < E > cellWrapper , String exceptionMessage ) ; void check ( CellWrapper < E > valueCell , RestDataTypeAdapter adapter ) ; String label ( String string ) ; void wrong ( CellWrapper < E > expected , RestDataTypeAdapter typeAdapter ) ; void right ( CellWrapper < E > expected , RestDataTypeAdapter typeAdapter ) ; String gray ( String string ) ; void asLink ( CellWrapper < E > cell , String link , String text ) ; void setDisplayActual ( boolean displayActual ) ; void setMinLenghtForToggleCollapse ( int minLen ) ; boolean isDisplayActual ( ) ; String fromRaw ( String text ) ; } </s> |
<s> package smartrics . rest . fitnesse . fixture . support ; import java . util . HashMap ; import java . util . Map ; import java . util . Map . Entry ; import java . util . regex . Matcher ; import java . util . regex . Pattern ; import fit . Fixture ; public class Variables { public static final Pattern VARIABLES_PATTERN = Pattern . compile ( "<STR_LIT>" ) ; private static final String FIT_NULL_VALUE = fitSymbolForNull ( ) ; private String nullValue = "<STR_LIT:null>" ; public Variables ( ) { this ( Config . getConfig ( ) ) ; } public Variables ( Config c ) { if ( c != null ) { this . nullValue = c . get ( "<STR_LIT>" , "<STR_LIT:null>" ) ; } } public void put ( String label , String val ) { String l = fromFitNesseSymbol ( label ) ; Fixture . setSymbol ( l , val ) ; } public String get ( String label ) { String l = fromFitNesseSymbol ( label ) ; if ( Fixture . hasSymbol ( l ) ) { return Fixture . getSymbol ( l ) . toString ( ) ; } return null ; } public void clearAll ( ) { Fixture . ClearSymbols ( ) ; } public String substitute ( String text ) { if ( text == null ) { return null ; } Matcher m = VARIABLES_PATTERN . matcher ( text ) ; Map < String , String > replacements = new HashMap < String , String > ( ) ; while ( m . find ( ) ) { int gc = m . groupCount ( ) ; if ( gc == <NUM_LIT:1> ) { String g0 = m . group ( <NUM_LIT:0> ) ; String g1 = m . group ( <NUM_LIT:1> ) ; String value = get ( g1 ) ; if ( FIT_NULL_VALUE . equals ( value ) ) { value = nullValue ; } replacements . put ( g0 , value ) ; } } String newText = text ; for ( Entry < String , String > en : replacements . entrySet ( ) ) { String k = en . getKey ( ) ; String replacement = replacements . get ( k ) ; if ( replacement != null ) { newText = newText . replaceAll ( k , replacement ) ; } } return newText ; } private String fromFitNesseSymbol ( String label ) { String l = label ; if ( l . startsWith ( "<STR_LIT:$>" ) ) { System . err . println ( "<STR_LIT>" + label + "<STR_LIT:)>" ) ; l = l . substring ( <NUM_LIT:1> ) ; } return l ; } private static String fitSymbolForNull ( ) { final String k = "<STR_LIT>" ; Fixture . setSymbol ( k , null ) ; return Fixture . getSymbol ( k ) . toString ( ) ; } public String replaceNull ( String s ) { if ( s == null ) { return nullValue ; } return s ; } } </s> |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.