/*
 * JBoss, Home of Professional Open Source
 * Copyright 2011, Red Hat Middleware LLC, and individual contributors
 * by the @authors tag. See the copyright.txt in the distribution for a
 * full listing of individual contributors.
 *
 * Licensed 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.jboss.aerogear.unifiedpush.test;

import org.jboss.aerogear.unifiedpush.api.PushApplication;
import org.jboss.aerogear.unifiedpush.dao.PageResult;
import org.jboss.aerogear.unifiedpush.dao.PushApplicationDao;

import javax.ejb.Stateless;
import javax.inject.Inject;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.core.Response;

@Stateless
@Path("/cleanup")
public class CleanupEndpoint {

    @Inject
    PushApplicationDao pushApplicationDao;

    @GET
    @Path("/applications")
    public Response cleanupApplications() {

        /* Retyping the count to int so it can be used in the findAll. It's basically impossible to have more than
         * 2^31 push applications and if so, we should fix this endpoint to allow long count. */
        int count = (int) pushApplicationDao.getNumberOfPushApplicationsForDeveloper();

        PageResult<PushApplication> pushApplicationPageResult = pushApplicationDao.findAll(0, count);

        for (PushApplication pushApplication : pushApplicationPageResult.getResultList()) {
            pushApplicationDao.delete(pushApplication);
        }

        return Response.ok().build();
    }

}

@@ -1128,21 +1128,133 @@
 .rs.
-core.Response
+Produces;%0Aimport javax.ws.rs.core.MediaType;%0Aimport javax.ws.rs.core.Response;%0Aimport java.util.HashMap;%0Aimport java.util.Map
 ;%0A%0A@
@@ -1405,16 +1405,58 @@
 tions%22)%0A
+    @Produces(MediaType.APPLICATION_JSON)%0A
     publ
@@ -1488,24 +1488,73 @@
 ations() %7B%0A%0A
+        long start = System.currentTimeMillis();%0A
         /* R
@@ -2104,16 +2104,223 @@
      %7D%0A%0A
+        long stop = System.currentTimeMillis();%0A%0A        Map%3CString, Object%3E response = new HashMap%3CString, Object%3E();%0A        response.put(%22cleaned%22, count);%0A        response.put(%22duration%22, stop - start);%0A
         
@@ -2338,16 +2338,24 @@
 onse.ok(
+response
 ).build(

Make applications cleanup endpoint respond with more information.