/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.apache.usergrid.rest.applications.collection.activities;


import com.fasterxml.jackson.databind.JsonNode;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import org.apache.usergrid.rest.AbstractRestIT;
import org.apache.usergrid.rest.TestContextSetup;
import org.apache.usergrid.rest.test.resource.CustomCollection;
import static org.apache.usergrid.utils.MapUtils.hashMap;
import static org.junit.Assert.assertEquals;
import org.junit.Rule;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


/**
 * Activity update test.
 */
public class PutTest extends AbstractRestIT {
    private static final Logger log= LoggerFactory.getLogger( PutTest.class );
    
    @Rule
    public TestContextSetup context = new TestContextSetup( this );

    @Test //USERGRID-545
    public void putMassUpdateTest() throws IOException {

        CustomCollection activities = context.customCollection( "activities" );

        Map actor = hashMap( "displayName", "Erin" );
        Map newActor = hashMap( "displayName", "Bob" );
        Map props = new HashMap();

        props.put( "actor", actor );
        props.put( "verb", "go" );
        props.put( "content", "bragh" );


        for ( int i = 0; i < 5; i++ ) {
            props.put( "ordinal", i );
            JsonNode activity = activities.create( props );
        }

        refreshIndex(context.getOrgName(), context.getAppName());

        String query = "select * ";

        JsonNode node = activities.withQuery( query ).get();
        String uuid = node.get( "entities" ).get( 0 ).get( "uuid" ).textValue();
        StringBuilder buf = new StringBuilder( uuid );

        activities.addToUrlEnd( buf );
        props.put( "actor", newActor );
        node = activities.put( props );

        refreshIndex(context.getOrgName(), context.getAppName());

        node = activities.withQuery( query ).get();
        assertEquals( 6, node.get( "entities" ).size() );
    }
}

@@ -990,32 +990,39 @@
 til.Map;%0Aimport 
+static 
 org.apache.userg
@@ -1029,28 +1029,77 @@
 rid.
-rest.AbstractRestIT;
+utils.MapUtils.hashMap;%0Aimport static org.junit.Assert.assertEquals;%0A
 %0Aimp
@@ -1127,32 +1127,117 @@
 id.rest.
-TestContextSetup
+test.resource.CollectionResource;%0Aimport org.apache.usergrid.rest.test.resource2point0.AbstractRestIT
 ;%0Aimport
@@ -1279,15 +1279,26 @@
 urce
-.Custom
+2point0.endpoints.
 Coll
@@ -1299,24 +1299,32 @@
 s.Collection
+Endpoint
 ;%0Aimport sta
@@ -1312,39 +1312,32 @@
 ndpoint;%0Aimport 
-static 
 org.apache.userg
@@ -1344,75 +1344,117 @@
 rid.
-utils.MapUtils.hashMap;%0Aimport static org.junit.Assert.assertEquals
+rest.test.resource2point0.model.Collection;%0Aimport org.apache.usergrid.rest.test.resource2point0.model.Entity
 ;%0Aim
@@ -1722,86 +1722,8 @@
     
-%0A    @Rule%0A    public TestContextSetup context = new TestContextSetup( this );
 %0A%0A  
@@ -1815,14 +1815,8 @@
     
-Custom
 Coll
@@ -1821,16 +1821,24 @@
 llection
+Endpoint
  activit
@@ -1847,23 +1847,20 @@
 s = 
-context.customC
+this.app().c
 olle
@@ -1865,17 +1865,16 @@
 lection(
- 
 %22activit
@@ -1877,17 +1877,16 @@
 ivities%22
- 
 );%0A%0A    
@@ -2233,24 +2233,22 @@
         
-JsonNode
+Entity
  activit
@@ -2266,22 +2266,30 @@
 ies.
-create( 
+post(new Entity(
 props
- 
+)
 );%0A 
@@ -2323,50 +2323,8 @@
 dex(
-context.getOrgName(), context.getAppName()
 );%0A%0A
@@ -2372,104 +2372,109 @@
     
-JsonNode node = activities.withQuery( query ).get();%0A        String uuid = node.get( %22e
+Collection collection = activities.get();%0A        String uuid = collection.getResponse().getE
 ntities
-%22 
+(
 ).ge
@@ -2487,28 +2487,23 @@
 .get
-( %22uuid%22 ).textValue
+Uuid().toString
 ();%0A
@@ -2557,25 +2557,24 @@
 uuid );%0A
-%0A
         
 activiti
@@ -2569,28 +2569,43 @@
     
-activities.addToUrlE
+buf.append( %22/%22 );%0A        buf.appe
 nd( 
@@ -2663,37 +2663,59 @@
     
-node = activities.put( 
+Entity activity = activities.post(new Entity(
 props
- 
+)
 );%0A%0A
@@ -2739,50 +2739,8 @@
 dex(
-context.getOrgName(), context.getAppName()
 );%0A%0A
@@ -2747,20 +2747,26 @@
         
-node
+collection
  = activ
@@ -2775,31 +2775,14 @@
 ies.
-withQuery( query ).
 get(
+  
 );%0A 
@@ -2809,29 +2809,45 @@
  6, 
-node.get( %22e
+collection.getResponse().getE
 ntities
-%22 
+(
 ).si

fix put test