usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From g...@apache.org
Subject usergrid git commit: Added additional test file and test case to verify the issue in USERGRID-144. Also, added fix to file not getting rid of text metadata and being properly replaced by image asset.
Date Tue, 12 Jan 2016 23:42:37 GMT
Repository: usergrid
Updated Branches:
  refs/heads/USERGRID-144 [created] d9d69d28e


Added additional test file and test case to verify the issue in USERGRID-144. Also, added
fix to file not getting rid of text metadata and being properly replaced by image asset.


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

Branch: refs/heads/USERGRID-144
Commit: d9d69d28e64d44a4bcb9efc3fb6d01e901e8cf8b
Parents: 3bb61da
Author: George Reyes <grey@apache.org>
Authored: Tue Jan 12 15:42:35 2016 -0800
Committer: George Reyes <grey@apache.org>
Committed: Tue Jan 12 15:42:35 2016 -0800

----------------------------------------------------------------------
 .../rest/applications/ServiceResource.java      | 11 ++-
 .../applications/assets/AssetResourceIT.java    | 80 ++++++++++++++++++++
 stack/rest/src/test/resources/test.txt          |  1 +
 3 files changed, 89 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/usergrid/blob/d9d69d28/stack/rest/src/main/java/org/apache/usergrid/rest/applications/ServiceResource.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/main/java/org/apache/usergrid/rest/applications/ServiceResource.java
b/stack/rest/src/main/java/org/apache/usergrid/rest/applications/ServiceResource.java
index 9956ff7..2809eb7 100644
--- a/stack/rest/src/main/java/org/apache/usergrid/rest/applications/ServiceResource.java
+++ b/stack/rest/src/main/java/org/apache/usergrid/rest/applications/ServiceResource.java
@@ -657,16 +657,20 @@ public class ServiceResource extends AbstractContextResource {
 
         FormDataBodyPart fileBodyPart = multiPart.getField( FILE_FIELD_NAME );
 
-        if ( data.isEmpty() && fileBodyPart != null ) { // ensure entity is created
even if there are no properties
+       // if ( data.isEmpty() && fileBodyPart != null ) { // ensure entity is created
even if there are no properties
             data.put( AssetUtils.FILE_METADATA, new HashMap() );
-        }
+       // }
 
         // process entity
         ApiResponse response = createApiResponse();
         response.setAction( serviceAction.name().toLowerCase() );
         response.setApplication( services.getApplication() );
         response.setParams( ui.getQueryParameters() );
+        if(data.get( FILE_FIELD_NAME )==null){
+            data.put( FILE_FIELD_NAME,null );
+        }
         ServicePayload payload = getPayload( data );
+
         ServiceResults serviceResults = executeServiceRequest( ui, response, serviceAction,
payload );
 
         // process file part
@@ -686,7 +690,8 @@ public class ServiceResource extends AbstractContextResource {
                     logger.error(re.getMessage());
                     response.setError( "500", re );
                 }
-                em.update( entity );
+                //em.update( entity );
+                entity = serviceResults.getEntity();
                 serviceResults.setEntity( entity );
             }
         }

http://git-wip-us.apache.org/repos/asf/usergrid/blob/d9d69d28/stack/rest/src/test/java/org/apache/usergrid/rest/applications/assets/AssetResourceIT.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/assets/AssetResourceIT.java
b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/assets/AssetResourceIT.java
index 8d647e7..a413c5c 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/assets/AssetResourceIT.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/assets/AssetResourceIT.java
@@ -111,6 +111,86 @@ public class AssetResourceIT extends AbstractRestIT {
 
 
     @Test
+    public void verifyMetadataChanged() throws Exception {
+
+        //resource.request().accept(MediaType.APPLICATION_OCTET_STREAM_TYPE).get(InputStream.class);
+
+        this.refreshIndex();
+
+        // post an entity
+
+        Map<String, String> payload = hashMap( "foo", "bar" );
+        ApiResponse postResponse = pathResource( getOrgAppPath( "foos" ) ).post( payload
);
+        UUID assetId = postResponse.getEntities().get(0).getUuid();
+        assertNotNull( assetId );
+
+        // post asset to that entity
+
+        byte[] data = IOUtils.toByteArray( this.getClass().getResourceAsStream( "/cassandra_eye.jpg"
) );
+        FormDataMultiPart form = new FormDataMultiPart()
+            .field( "foo", "bar2" )
+            .field( "file", data, MediaType.MULTIPART_FORM_DATA_TYPE );
+        ApiResponse putResponse = pathResource( getOrgAppPath( "foos/" + assetId ) ).put(
form );
+        this.refreshIndex();
+
+        // get entity and check asset metadata
+
+        ApiResponse getResponse = pathResource( getOrgAppPath( "foos/" + assetId ) ).get(
ApiResponse.class );
+        Entity entity = getResponse.getEntities().get( 0 );
+        Map<String, Object> fileMetadata = (Map<String, Object>)entity.get("file-metadata");
+        long lastModified = Long.parseLong( fileMetadata.get( AssetUtils.LAST_MODIFIED ).toString()
);
+
+        assertEquals( assetId,      entity.getUuid() );
+        assertEquals( "bar2",       entity.get("foo") );
+        assertEquals( "image/jpeg", fileMetadata.get( AssetUtils.CONTENT_TYPE ) );
+        assertEquals( 7979,         fileMetadata.get( AssetUtils.CONTENT_LENGTH ));
+
+        // get asset and check size
+
+        InputStream is = pathResource( getOrgAppPath( "foos/" + assetId ) ).getAssetAsStream();
+        byte[] foundData = IOUtils.toByteArray( is );
+        assertEquals( 7979, foundData.length );
+
+        // upload new asset to entity, then check that it was updated
+
+
+        data = IOUtils.toByteArray( this.getClass().getResourceAsStream( "/test.txt" ) );
+        form = new FormDataMultiPart()
+            .field( "foo", "bar2" )
+            .field( "file", data,MediaType.MULTIPART_FORM_DATA_TYPE);
+
+        ApiResponse putResponse2 = pathResource( getOrgAppPath( "foos/" + assetId ) ).put(
form );
+        entity = putResponse2.getEntities().get( 0 );
+        fileMetadata = (Map<String, Object>)entity.get("file-metadata");
+        long justModified = Long.parseLong( fileMetadata.get( AssetUtils.LAST_MODIFIED ).toString()
);
+        assertNotEquals( lastModified, justModified );
+
+        assertEquals( assetId,      entity.getUuid() );
+        assertEquals( "text/plain", fileMetadata.get( AssetUtils.CONTENT_TYPE ) );
+        assertEquals( 76,         fileMetadata.get( AssetUtils.CONTENT_LENGTH ));
+
+        //now change it back to the picture asset
+        data = IOUtils.toByteArray( this.getClass().getResourceAsStream( "/cassandra_eye.jpg"
) );
+        form = new FormDataMultiPart()
+            .field( "foo", "bar2" )
+            .field( "file", data, MediaType.MULTIPART_FORM_DATA_TYPE );
+        putResponse = pathResource( getOrgAppPath( "foos/" + assetId ) ).put( form );
+        this.refreshIndex();
+
+
+        getResponse = pathResource( getOrgAppPath( "foos/" + assetId ) ).get( ApiResponse.class
);
+        entity = getResponse.getEntities().get( 0 );
+        fileMetadata = (Map<String, Object>)entity.get("file-metadata");
+        Long.parseLong( fileMetadata.get( AssetUtils.LAST_MODIFIED ).toString() );
+
+        assertEquals( assetId,      entity.getUuid() );
+        assertEquals( "bar2",       entity.get("foo") );
+        assertEquals( "image/jpeg", fileMetadata.get( AssetUtils.CONTENT_TYPE ) );
+        assertEquals( 7979,         fileMetadata.get( AssetUtils.CONTENT_LENGTH ));
+    }
+
+
+    @Test
     public void multipartPostFormOnDynamicEntity() throws Exception {
 
         this.refreshIndex();

http://git-wip-us.apache.org/repos/asf/usergrid/blob/d9d69d28/stack/rest/src/test/resources/test.txt
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/resources/test.txt b/stack/rest/src/test/resources/test.txt
new file mode 100644
index 0000000..79a34fc
--- /dev/null
+++ b/stack/rest/src/test/resources/test.txt
@@ -0,0 +1 @@
+random text to test assets and how they handle differing file formats here.


Mime
View raw message