@Test
public void testDelete() throws Exception {
ServiceImplementation impl = getServiceImplementation();
RulesRepository repo = impl.getRulesRepository();
PackageItem pkg = repo.createPackage( "testDeleteRestServlet",
"" );
AssetItem ass = pkg.addAsset( "asset1",
"abc" );
ass.updateFormat( "drl" );
ass.checkin( "" );
MockIdentity midentity = new MockIdentity();
midentity.setIsLoggedIn( false );
midentity.setAllowLogin( true );
Contexts.getSessionContext().set( "org.jboss.seam.security.identity",
midentity );
FileManagerUtils manager = new FileManagerUtils();
manager.setRepository( repo );
Contexts.getSessionContext().set( "fileManager",
manager );
Contexts.getSessionContext().set( "repository",
repo );
Map<String, String> headers = new HashMap<String, String>() {
{
put( "Authorization",
"BASIC " + new String( Base64.encodeBase64( "test:password".getBytes() ) ) );
}
};
ByteArrayInputStream in = new ByteArrayInputStream( "some new content".getBytes() );
RestAPIServlet serv = new RestAPIServlet();
MockHTTPRequest req = new MockHTTPRequest( "http://foo/api/packages/testDeleteRestServlet/asset1.drl",
headers,
in );
MockHTTPResponse res = new MockHTTPResponse();
serv.doDelete( req,
res );
assertEquals( "OK",
res.extractContent() );
pkg = repo.loadPackage( "testDeleteRestServlet" );
assertFalse( pkg.listAssetsByFormat( new String[]{"drl"} ).hasNext() );
repo.logout();
Lifecycle.endApplication();
}