usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From snoopd...@apache.org
Subject [33/50] [abbrv] git commit: Added a fake payload builder to my export tests. Using TDD metrology from here on forward. Added get endpoint that queries for job status. Removed original code from MockS3Export. Currently code does not work due to features n
Date Tue, 25 Feb 2014 06:21:47 GMT
Added a fake payload builder to my export tests. Using TDD metrology from here on forward.
Added get endpoint that queries for job status.
Removed original code from MockS3Export.
Currently code does not work due to features not being fully implemented yet.


Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/871a9a57
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/871a9a57
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/871a9a57

Branch: refs/pull/60/head
Commit: 871a9a578d232a8081aa83941c5b7441b9fd8244
Parents: 5137656
Author: grey <greyes@apigee.com>
Authored: Mon Feb 17 07:52:27 2014 -0800
Committer: grey <greyes@apigee.com>
Committed: Mon Feb 17 07:52:27 2014 -0800

----------------------------------------------------------------------
 .../rest/management/ManagementResource.java     | 15 ++++-
 .../rest/management/ManagementResourceIT.java   | 66 +++++++++++++++++++-
 .../management/export/ExportServiceImpl.java    |  8 +++
 .../management/cassandra/MockS3ExportImpl.java  | 55 ----------------
 4 files changed, 86 insertions(+), 58 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/871a9a57/stack/rest/src/main/java/org/usergrid/rest/management/ManagementResource.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/main/java/org/usergrid/rest/management/ManagementResource.java
b/stack/rest/src/main/java/org/usergrid/rest/management/ManagementResource.java
index 8f802bd..99b1dc4 100644
--- a/stack/rest/src/main/java/org/usergrid/rest/management/ManagementResource.java
+++ b/stack/rest/src/main/java/org/usergrid/rest/management/ManagementResource.java
@@ -453,10 +453,8 @@ public class ManagementResource extends AbstractContextResource {
 
     @POST
     @Path( "export" )
-   // @RequireAdminUserAccess
     @Consumes(MediaType.APPLICATION_JSON)
     public Response exportPostJson (@Context UriInfo ui,
-                                   // @QueryParam( "access_token" ) String access_token,
                                     Map<String, Object> json,
                                     @QueryParam( "callback" ) @DefaultValue( "" ) String
callback)
             throws OAuthSystemException {
@@ -495,6 +493,19 @@ public class ManagementResource extends AbstractContextResource {
                  //      .entity( wrapWithCallback( "", callback ) ).build();
     }
 
+    @GET
+    @Path( "export" )
+    @Consumes(MediaType.APPLICATION_JSON)
+    public Response exportGetJson (@Context UriInfo ui,
+                                   Map<String, Object> json,
+                                   @QueryParam( "callback" ) @DefaultValue( "" ) String callback)
{
+
+
+
+
+        return Response.status(SC_OK).entity(jobStatus).build();
+    }
+
 
     String errorMsg = "";
     String responseType;

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/871a9a57/stack/rest/src/test/java/org/usergrid/rest/management/ManagementResourceIT.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/usergrid/rest/management/ManagementResourceIT.java
b/stack/rest/src/test/java/org/usergrid/rest/management/ManagementResourceIT.java
index 87a1d18..71b346f 100644
--- a/stack/rest/src/test/java/org/usergrid/rest/management/ManagementResourceIT.java
+++ b/stack/rest/src/test/java/org/usergrid/rest/management/ManagementResourceIT.java
@@ -634,7 +634,7 @@ public class ManagementResourceIT extends AbstractRestIT {
         payload.put( "properties", properties);
 
         try {
-            node = resource().path( "/management/export" ).queryParam( "access_token", adminAccessToken
)
+            node = resource().path( "/management/export" )
                              .accept( MediaType.APPLICATION_JSON )
                              .type( MediaType.APPLICATION_JSON_TYPE ).post( JsonNode.class,
payload );
 
@@ -646,5 +646,69 @@ public class ManagementResourceIT extends AbstractRestIT {
         assertEquals( Status.ACCEPTED, responseStatus );
         assertNotNull( node.get( "jobUUID" ) );
     }
+/*Make a test with an invalid uuid and a wrong uuid.*/
+    @Test
+    public void exportGetJobStatTest() throws Exception {
+        JsonNode node = null;
+        Status responseStatus = Status.OK;
+
+        HashMap<String, Object> payload = payloadBuilder();
+
+        node = resource().path( "/management/export" )
+                         .accept( MediaType.APPLICATION_JSON )
+                         .type( MediaType.APPLICATION_JSON_TYPE ).post( JsonNode.class, payload
);
+
+        try {
+            node = resource().path( "/management/export/"+node.get("jobUUID") ).accept( MediaType.APPLICATION_JSON
).type( MediaType.APPLICATION_JSON_TYPE )
+                .get( JsonNode.class );
+        }catch(UniformInterfaceException uie) {
+            responseStatus = uie.getResponse().getClientResponseStatus();
+        }
+
+        assertEquals( Status.OK,responseStatus );
+        assertEquals( "PENDING",node.get( "jobStatus" ) );
+
+    }
+
+    @Test
+    public void exportGetWrongUUID() throws Exception {
+        JsonNode node = null;
+        Status responseStatus = Status.BAD_REQUEST;
+
+        try {
+            node = resource().path(
+                "/management/export/123456789" ).accept( MediaType.APPLICATION_JSON ).type(
+                MediaType.APPLICATION_JSON_TYPE )
+                        .get( JsonNode.class );
+        }catch(UniformInterfaceException uie) {
+            responseStatus = uie.getResponse().getClientResponseStatus();
+        }
+
+        assertEquals(Status.BAD_REQUEST, responseStatus);
+        assertEquals( "No Such Job", node.get( "jobStatus" ) );
+
+    }
+
+    /*Creates fake payload for testing purposes.*/
+    public HashMap<String,Object> payloadBuilder() {
+        HashMap<String, Object> payload = new HashMap<String, Object>();
+        Map<String, Object> properties = new HashMap<String, Object>();
+        Map<String, Object> storage_info = new HashMap<String, Object>();
+        //TODO: make sure to put a valid admin token here.
+        //storage_info.put( "admin_token","insert_token_data_here" );
+        //TODO: always put dummy values here and ignore this test.
+        //TODO: add a ret for when s3 values are invalid.
+        storage_info.put( "s3_key","insert key here" );
+        storage_info.put( "s3_accessId","insert access id here");
+        storage_info.put( "bucket_location","insert bucket name here");
+
+
+        properties.put( "storage_provider","s3");
+        properties.put( "storage_info",storage_info);
+
+        payload.put( "path", "test-organization/test-app/user");
+        payload.put( "properties", properties);
+        return payload;
+    }
 
 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/871a9a57/stack/services/src/main/java/org/usergrid/management/export/ExportServiceImpl.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/usergrid/management/export/ExportServiceImpl.java
b/stack/services/src/main/java/org/usergrid/management/export/ExportServiceImpl.java
index 287813d..c99b4f6 100644
--- a/stack/services/src/main/java/org/usergrid/management/export/ExportServiceImpl.java
+++ b/stack/services/src/main/java/org/usergrid/management/export/ExportServiceImpl.java
@@ -121,6 +121,14 @@ public class ExportServiceImpl implements ExportService {
             logger.error( "could not get stats for job" );
         }
     }
+//things I need to learn how to do, how to add states to my job and then set them in my export
info such that I can
+    //access them using a uuid.
+    public JobStat getJobStatus( final String uuid) throws Exception {
+        UUID jobId = UUID.fromString( uuid );
+        JobStat jobStat = sch.getStatsForJob( "exportJob", jobId );
+      //  return jobStat.get
+        return jobStat;
+    }
 
 
     @Override

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/871a9a57/stack/services/src/test/java/org/usergrid/management/cassandra/MockS3ExportImpl.java
----------------------------------------------------------------------
diff --git a/stack/services/src/test/java/org/usergrid/management/cassandra/MockS3ExportImpl.java
b/stack/services/src/test/java/org/usergrid/management/cassandra/MockS3ExportImpl.java
index 604c1bb..f66b67d 100644
--- a/stack/services/src/test/java/org/usergrid/management/cassandra/MockS3ExportImpl.java
+++ b/stack/services/src/test/java/org/usergrid/management/cassandra/MockS3ExportImpl.java
@@ -45,60 +45,5 @@ public class MockS3ExportImpl implements S3Export {
         catch ( IOException e ) {
             e.printStackTrace();
         }
-
-
-
-
-
-        //        Logger logger = LoggerFactory.getLogger( ExportServiceImpl.class );
-//        /*won't need any of the properties as I have the export info*/
-//        String bucketName = exportInfo.getBucket_location();
-//        String accessId = exportInfo.getS3_accessId();
-//        String secretKey = exportInfo.getS3_key();
-//
-//        Properties overrides = new Properties();
-//        overrides.setProperty( "s3" + ".identity", accessId );
-//        overrides.setProperty( "s3" + ".credential", secretKey );
-//
-//        final Iterable<? extends Module> MODULES = ImmutableSet
-//                .of( new JavaUrlHttpCommandExecutorServiceModule(), new Log4JLoggingModule(),
new NettyPayloadModule
-//                        () );
-//
-//        BlobStoreContext context =
-//                ContextBuilder.newBuilder( "s3" ).credentials( accessId, secretKey ).modules(
MODULES )
-//                              .overrides( overrides ).buildView( BlobStoreContext.class
);
-//
-//        // Create Container (the bucket in s3)
-//        try {
-//            AsyncBlobStore blobStore = context.getAsyncBlobStore(); // it can be changed
to sync
-//            // BlobStore (returns false if it already exists)
-//            ListenableFuture<Boolean> container = blobStore.createContainerInLocation(
null, bucketName );
-//            if ( container.get() ) {
-//                logger.info( "Created bucket " + bucketName );
-//            }
-//        }
-//        catch ( Exception ex ) {
-//            logger.error( "Could not start binary service: {}", ex.getMessage() );
-//            //throw new RuntimeException( ex );
-//        }
-//
-//        try {
-//
-//
-//            AsyncBlobStore blobStore = context.getAsyncBlobStore();
-//            BlobBuilder blobBuilder =
-//                    blobStore.blobBuilder( filename ).payload( inputStream ).calculateMD5().contentType(
"text/plain" );
-//
-//
-//            Blob blob = blobBuilder.build();
-//
-//            ListenableFuture<String> futureETag = blobStore.putBlob( bucketName,
blob, PutOptions.Builder.multipart() );
-//
-//            logger.info( "Uploaded file etag=" + futureETag.get() );
-//        }
-//        catch ( Exception e ) {
-//            logger.error( "Error uploading to blob store", e );
-//        }
-
     }
 }


Mime
View raw message