@Test
public void testPut() throws Exception {
ServiceImplementation impl = getServiceImplementation();
RulesRepository repo = impl.getRulesRepository();
PackageItem pkg = repo.createPackage( "testPutRestServlet",
"" );
AssetItem ass = pkg.addAsset( "asset1",
"abc" );
ass.updateFormat( "drl" );
ass.checkin( "" );
long ver = ass.getVersionNumber();
MockIdentity midentity = new MockIdentity();
midentity.setIsLoggedIn( false );
midentity.setAllowLogin( true );
Contexts.getSessionContext().set( "org.jboss.seam.security.identity",
midentity );
Map<String, String> headers = new HashMap<String, String>() {
{
put( "Authorization",
"BASIC " + new String( Base64.encodeBase64( "test:password".getBytes() ) ) );
put( "Checkin-Comment",
"hey ho" );
}
};
ByteArrayInputStream in = new ByteArrayInputStream( "some new content".getBytes() );
RestAPIServlet serv = new RestAPIServlet();
MockHTTPRequest req = new MockHTTPRequest( "http://foo/api/packages/testPutRestServlet/asset1.drl",
headers,
in );
MockHTTPResponse res = new MockHTTPResponse();
serv.doPut( req,
res );
assertEquals( "OK",
res.extractContent() );
ass = pkg.loadAsset( "asset1" );
pkg.getNode().refresh( false );
assertEquals( "some new content",
ass.getContent() );
assertEquals( ver + 1,
ass.getVersionNumber() );
assertEquals( "hey ho",
ass.getCheckinComment() );
repo.logout();
Lifecycle.endApplication();
}