Package org.exoplatform.services.rest.impl

Examples of org.exoplatform.services.rest.impl.ContainerResponse


                  new ContainerRequestUserRole("GET", new URI(HTTP_BACKUP_AGENT_PATH
                           + HTTPBackupAgent.Constants.OperationType.COMPLETED_BACKUPS_REPOSITORY_INFO), new URI(""),
                           null, new InputHeadersMap(headers));

         ByteArrayContainerResponseWriter responseWriter = new ByteArrayContainerResponseWriter();
         ContainerResponse cres = new ContainerResponse(responseWriter);
         handler.handleRequest(creq, cres);

         assertEquals(200, cres.getStatus());

         ShortInfoList infoList = (ShortInfoList) getObject(ShortInfoList.class, responseWriter.getBody());
         List<ShortInfo> list = new ArrayList<ShortInfo>(infoList.getBackups());

         ShortInfo info = getBackupInfo(list);
         assertNotNull(info);

         assertEquals(info.getRepositoryName(), "db6");

         id = info.getBackupId();
      }

      // Getting default RepositoryEntry
      RepositoryEntry defREntry;
      {
         MultivaluedMap<String, String> headers = new MultivaluedMapImpl();
         ContainerRequestUserRole creq =
                  new ContainerRequestUserRole("GET", new URI(HTTP_BACKUP_AGENT_PATH
                           + HTTPBackupAgent.Constants.OperationType.GET_DEFAULT_REPOSITORY_CONFIG), new URI(""), null,
                           new InputHeadersMap(headers));

         ByteArrayContainerResponseWriter responseWriter = new ByteArrayContainerResponseWriter();
         ContainerResponse cres = new ContainerResponse(responseWriter);
         handler.handleRequest(creq, cres);

         assertEquals(200, cres.getStatus());
         defREntry = (RepositoryEntry) getObject(RepositoryEntry.class, responseWriter.getBody());
      }

      // Getting default WorkspaceEntry
      WorkspaceEntry defWEntry;
      {
         MultivaluedMap<String, String> headers = new MultivaluedMapImpl();
         ContainerRequestUserRole creq =
                  new ContainerRequestUserRole("GET", new URI(HTTP_BACKUP_AGENT_PATH
                           + HTTPBackupAgent.Constants.OperationType.GET_DEFAULT_WORKSPACE_CONFIG), new URI(""), null,
                           new InputHeadersMap(headers));

         ByteArrayContainerResponseWriter responseWriter = new ByteArrayContainerResponseWriter();
         ContainerResponse cres = new ContainerResponse(responseWriter);
         handler.handleRequest(creq, cres);

         assertEquals(200, cres.getStatus());
         defWEntry = (WorkspaceEntry) getObject(WorkspaceEntry.class, responseWriter.getBody());
      }

      ArrayList<WorkspaceEntry> wsEntries = new ArrayList<WorkspaceEntry>();
      wsEntries.add(makeWorkspaceEntry(defWEntry, "db6backup", "ws", "jdbcjcr27"));
      wsEntries.add(makeWorkspaceEntry(defWEntry, "db6backup", "ws2", "jdbcjcr27"));
      RepositoryEntry rEntry = makeRepositoryEntry(defREntry, "db6backup", wsEntries);

      // Check the repository /db6backup.
      try
      {
         repositoryService.getRepository("db6backup");
         // ok
      }
      catch (Exception e)
      {
         fail("The repository /db6backup should be exists.");
      }

      // Restore
      {
         // Create JSON to WorkspaceEntry
         JsonGeneratorImpl generatorImpl = new JsonGeneratorImpl();
         JsonValue json = generatorImpl.createJsonObject(rEntry);

         // Execute restore
         MultivaluedMap<String, String> headers = new MultivaluedMapImpl();
         headers.putSingle("Content-Type", "application/json; charset=UTF-8");
         ContainerRequestUserRole creq =
                  new ContainerRequestUserRole("POST", new URI(HTTP_BACKUP_AGENT_PATH
                           + HTTPBackupAgent.Constants.OperationType.RESTORE_REPOSITORY + "/" + id + "/" + "true"),
                           new URI(""),
                           new ByteArrayInputStream(json.toString().getBytes("UTF-8")), new InputHeadersMap(headers));

         ByteArrayContainerResponseWriter responseWriter = new ByteArrayContainerResponseWriter();
         ContainerResponse cres = new ContainerResponse(responseWriter);
         handler.handleRequest(creq, cres);

         assertEquals(200, cres.getStatus());
      }

      waitRepositoryRestore("db6backup");

      // Get restore info
      {
         MultivaluedMap<String, String> headers = new MultivaluedMapImpl();
         ContainerRequestUserRole creq =
                  new ContainerRequestUserRole("GET", new URI(HTTP_BACKUP_AGENT_PATH
                           + HTTPBackupAgent.Constants.OperationType.CURRENT_RESTORE_INFO_ON_REPOSITORY + "/"
                           + "db6backup"), new URI(""), null, new InputHeadersMap(headers));

         ByteArrayContainerResponseWriter responseWriter = new ByteArrayContainerResponseWriter();
         ContainerResponse cres = new ContainerResponse(responseWriter);
         handler.handleRequest(creq, cres);

         assertEquals(200, cres.getStatus());

         DetailedInfo info = (DetailedInfo) getObject(DetailedInfo.class, responseWriter.getBody());

         assertNotNull(info);
         assertEquals(BackupManager.FULL_AND_INCREMENTAL, info.getBackupType().intValue());
View Full Code Here


                  new ContainerRequestUserRole("GET", new URI(HTTP_BACKUP_AGENT_PATH
                           + HTTPBackupAgent.Constants.OperationType.COMPLETED_BACKUPS_REPOSITORY_INFO), new URI(""),
                           null, new InputHeadersMap(headers));

         ByteArrayContainerResponseWriter responseWriter = new ByteArrayContainerResponseWriter();
         ContainerResponse cres = new ContainerResponse(responseWriter);
         handler.handleRequest(creq, cres);

         assertEquals(200, cres.getStatus());

         ShortInfoList infoList = (ShortInfoList) getObject(ShortInfoList.class, responseWriter.getBody());
         List<ShortInfo> list = new ArrayList<ShortInfo>(infoList.getBackups());

         ShortInfo info = getBackupInfo(list);
         assertNotNull(info);

         assertEquals(info.getRepositoryName(), "db6");

         id = info.getBackupId();
      }

      // Getting default RepositoryEntry
      RepositoryEntry defREntry;
      {
         MultivaluedMap<String, String> headers = new MultivaluedMapImpl();
         ContainerRequestUserRole creq =
                  new ContainerRequestUserRole("GET", new URI(HTTP_BACKUP_AGENT_PATH
                           + HTTPBackupAgent.Constants.OperationType.GET_DEFAULT_REPOSITORY_CONFIG), new URI(""), null,
                           new InputHeadersMap(headers));

         ByteArrayContainerResponseWriter responseWriter = new ByteArrayContainerResponseWriter();
         ContainerResponse cres = new ContainerResponse(responseWriter);
         handler.handleRequest(creq, cres);

         assertEquals(200, cres.getStatus());
         defREntry = (RepositoryEntry) getObject(RepositoryEntry.class, responseWriter.getBody());
      }

      // Getting default WorkspaceEntry
      WorkspaceEntry defWEntry;
      {
         MultivaluedMap<String, String> headers = new MultivaluedMapImpl();
         ContainerRequestUserRole creq =
                  new ContainerRequestUserRole("GET", new URI(HTTP_BACKUP_AGENT_PATH
                           + HTTPBackupAgent.Constants.OperationType.GET_DEFAULT_WORKSPACE_CONFIG), new URI(""), null,
                           new InputHeadersMap(headers));

         ByteArrayContainerResponseWriter responseWriter = new ByteArrayContainerResponseWriter();
         ContainerResponse cres = new ContainerResponse(responseWriter);
         handler.handleRequest(creq, cres);

         assertEquals(200, cres.getStatus());
         defWEntry = (WorkspaceEntry) getObject(WorkspaceEntry.class, responseWriter.getBody());
      }

      ArrayList<WorkspaceEntry> wsEntries = new ArrayList<WorkspaceEntry>();
      wsEntries.add(makeWorkspaceEntry(defWEntry, "db6backup", "ws", "jdbcjcr27"));
      wsEntries.add(makeWorkspaceEntry(defWEntry, "db6backup", "ws2", "jdbcjcr27"));
      RepositoryEntry rEntry = makeRepositoryEntry(defREntry, "db6backup", wsEntries);

      removeRepositoryFully("db6backup");
      // Check the repository /db6backup.
      try
      {
         repositoryService.getRepository("db6backup");
         fail("The repository /db6backup should be not exists.");
      }
      catch (Exception e)
      {
         // ok
      }

      // Restore
      {
         // Create JSON to WorkspaceEntry
         JsonGeneratorImpl generatorImpl = new JsonGeneratorImpl();
         JsonValue json = generatorImpl.createJsonObject(rEntry);

         // Execute restore
         MultivaluedMap<String, String> headers = new MultivaluedMapImpl();
         headers.putSingle("Content-Type", "application/json; charset=UTF-8");
         ContainerRequestUserRole creq =
                  new ContainerRequestUserRole("POST", new URI(HTTP_BACKUP_AGENT_PATH
                           + HTTPBackupAgent.Constants.OperationType.RESTORE_REPOSITORY + "/" + id + "/" + "false"),
                           new URI(""), new ByteArrayInputStream(json.toString().getBytes("UTF-8")),
                           new InputHeadersMap(headers));

         ByteArrayContainerResponseWriter responseWriter = new ByteArrayContainerResponseWriter();
         ContainerResponse cres = new ContainerResponse(responseWriter);
         handler.handleRequest(creq, cres);

         assertEquals(200, cres.getStatus());
      }

      waitRepositoryRestore("db6backup");

      // Get restore info
      {
         MultivaluedMap<String, String> headers = new MultivaluedMapImpl();
         ContainerRequestUserRole creq =
                  new ContainerRequestUserRole("GET", new URI(HTTP_BACKUP_AGENT_PATH
                           + HTTPBackupAgent.Constants.OperationType.CURRENT_RESTORE_INFO_ON_REPOSITORY + "/"
                           + "db6backup"), new URI(""), null, new InputHeadersMap(headers));

         ByteArrayContainerResponseWriter responseWriter = new ByteArrayContainerResponseWriter();
         ContainerResponse cres = new ContainerResponse(responseWriter);
         handler.handleRequest(creq, cres);

         assertEquals(200, cres.getStatus());

         DetailedInfo info = (DetailedInfo) getObject(DetailedInfo.class, responseWriter.getBody());

         assertNotNull(info);
         assertEquals(BackupManager.FULL_AND_INCREMENTAL, info.getBackupType().intValue());
View Full Code Here

                  new ContainerRequestUserRole("GET", new URI(HTTP_BACKUP_AGENT_PATH
                           + HTTPBackupAgent.Constants.OperationType.COMPLETED_BACKUPS_REPOSITORY_INFO), new URI(""),
                           null, new InputHeadersMap(headers));

         ByteArrayContainerResponseWriter responseWriter = new ByteArrayContainerResponseWriter();
         ContainerResponse cres = new ContainerResponse(responseWriter);
         handler.handleRequest(creq, cres);

         assertEquals(200, cres.getStatus());

         ShortInfoList infoList = (ShortInfoList) getObject(ShortInfoList.class, responseWriter.getBody());
         List<ShortInfo> list = new ArrayList<ShortInfo>(infoList.getBackups());

         ShortInfo info = getBackupInfo(list);
         assertNotNull(info);

         assertEquals(info.getRepositoryName(), "db6");

         id = info.getBackupId();
      }

      // Check the repository /db6backup.
      try
      {
         repositoryService.getRepository("db6");
         // ok
      }
      catch (Exception e)
      {
         fail("The repository /db6 should be exists.");
      }

      // Restore
      {
         // Execute restore
         MultivaluedMap<String, String> headers = new MultivaluedMapImpl();
         ContainerRequestUserRole creq =
                  new ContainerRequestUserRole("GET", new URI(HTTP_BACKUP_AGENT_PATH
                           + HTTPBackupAgent.Constants.OperationType.RESTORE_REPOSITORY + "/" + id + "/" + "true"),
                           new URI(""), null,
                           new InputHeadersMap(headers));

         ByteArrayContainerResponseWriter responseWriter = new ByteArrayContainerResponseWriter();
         ContainerResponse cres = new ContainerResponse(responseWriter);
         handler.handleRequest(creq, cres);

         assertEquals(200, cres.getStatus());
      }

      waitRepositoryRestore("db6");

      // Get restore info
      {
         MultivaluedMap<String, String> headers = new MultivaluedMapImpl();
         ContainerRequestUserRole creq =
                  new ContainerRequestUserRole("GET", new URI(HTTP_BACKUP_AGENT_PATH
                           + HTTPBackupAgent.Constants.OperationType.CURRENT_RESTORE_INFO_ON_REPOSITORY + "/" + "db6"),
                           new URI(""), null, new InputHeadersMap(headers));

         ByteArrayContainerResponseWriter responseWriter = new ByteArrayContainerResponseWriter();
         ContainerResponse cres = new ContainerResponse(responseWriter);
         handler.handleRequest(creq, cres);

         assertEquals(200, cres.getStatus());

         DetailedInfo info = (DetailedInfo) getObject(DetailedInfo.class, responseWriter.getBody());

         assertNotNull(info);
         assertEquals(BackupManager.FULL_AND_INCREMENTAL, info.getBackupType().intValue());
View Full Code Here

                  new ContainerRequestUserRole("GET", new URI(HTTP_BACKUP_AGENT_PATH
                           + HTTPBackupAgent.Constants.OperationType.COMPLETED_BACKUPS_REPOSITORY_INFO), new URI(""),
                           null, new InputHeadersMap(headers));

         ByteArrayContainerResponseWriter responseWriter = new ByteArrayContainerResponseWriter();
         ContainerResponse cres = new ContainerResponse(responseWriter);
         handler.handleRequest(creq, cres);

         assertEquals(200, cres.getStatus());

         ShortInfoList infoList = (ShortInfoList) getObject(ShortInfoList.class, responseWriter.getBody());
         List<ShortInfo> list = new ArrayList<ShortInfo>(infoList.getBackups());

         ShortInfo info = getBackupInfo(list);
         assertNotNull(info);

         assertEquals(info.getRepositoryName(), "db6");

         id = info.getBackupId();
      }

      removeRepositoryFully("db6");
      // Check the repository /db6backup.
      try
      {
         repositoryService.getRepository("db6");
         fail("The repository /db6 should be not exists.");
      }
      catch (Exception e)
      {
         // ok
      }

      // Restore
      {
         // Execute restore
         MultivaluedMap<String, String> headers = new MultivaluedMapImpl();
         ContainerRequestUserRole creq =
                  new ContainerRequestUserRole("GET", new URI(HTTP_BACKUP_AGENT_PATH
                           + HTTPBackupAgent.Constants.OperationType.RESTORE_REPOSITORY + "/" + id + "/" + "false"),
                           new URI(""), null, new InputHeadersMap(headers));

         ByteArrayContainerResponseWriter responseWriter = new ByteArrayContainerResponseWriter();
         ContainerResponse cres = new ContainerResponse(responseWriter);
         handler.handleRequest(creq, cres);

         assertEquals(200, cres.getStatus());
      }

      waitRepositoryRestore("db6");

      // Get restore info
      {
         MultivaluedMap<String, String> headers = new MultivaluedMapImpl();
         ContainerRequestUserRole creq =
                  new ContainerRequestUserRole("GET", new URI(HTTP_BACKUP_AGENT_PATH
                           + HTTPBackupAgent.Constants.OperationType.CURRENT_RESTORE_INFO_ON_REPOSITORY + "/" + "db6"),
                           new URI(""), null, new InputHeadersMap(headers));

         ByteArrayContainerResponseWriter responseWriter = new ByteArrayContainerResponseWriter();
         ContainerResponse cres = new ContainerResponse(responseWriter);
         handler.handleRequest(creq, cres);

         assertEquals(200, cres.getStatus());

         DetailedInfo info = (DetailedInfo) getObject(DetailedInfo.class, responseWriter.getBody());

         assertNotNull(info);
         assertEquals(BackupManager.FULL_AND_INCREMENTAL, info.getBackupType().intValue());
View Full Code Here

                  new ContainerRequestUserRole("GET", new URI(HTTP_BACKUP_AGENT_PATH
                           + HTTPBackupAgent.Constants.OperationType.COMPLETED_BACKUPS_REPOSITORY_INFO), new URI(""),
                           null, new InputHeadersMap(headers));

         ByteArrayContainerResponseWriter responseWriter = new ByteArrayContainerResponseWriter();
         ContainerResponse cres = new ContainerResponse(responseWriter);
         handler.handleRequest(creq, cres);

         assertEquals(200, cres.getStatus());

         ShortInfoList infoList = (ShortInfoList) getObject(ShortInfoList.class, responseWriter.getBody());
         List<ShortInfo> list = new ArrayList<ShortInfo>(infoList.getBackups());

         ShortInfo info = getBackupInfo(list);
         assertNotNull(info);

         assertEquals(info.getRepositoryName(), "db6");

         id = info.getBackupId();

         for (RepositoryBackupChainLog bcl : backup.getRepositoryBackupsLogs())
         {
            if (bcl.getBackupId().equals(id))
            {
               backupSetPath = URLEncoder.encode(bcl.getBackupConfig().getBackupDir().getCanonicalPath(), "UTF-8");
               break;
            }
         }
      }

      // Getting default RepositoryEntry
      RepositoryEntry defREntry;
      {
         MultivaluedMap<String, String> headers = new MultivaluedMapImpl();
         ContainerRequestUserRole creq =
                  new ContainerRequestUserRole("GET", new URI(HTTP_BACKUP_AGENT_PATH
                           + HTTPBackupAgent.Constants.OperationType.GET_DEFAULT_REPOSITORY_CONFIG), new URI(""), null,
                           new InputHeadersMap(headers));

         ByteArrayContainerResponseWriter responseWriter = new ByteArrayContainerResponseWriter();
         ContainerResponse cres = new ContainerResponse(responseWriter);
         handler.handleRequest(creq, cres);

         assertEquals(200, cres.getStatus());
         defREntry = (RepositoryEntry) getObject(RepositoryEntry.class, responseWriter.getBody());
      }

      // Getting default WorkspaceEntry
      WorkspaceEntry defWEntry;
      {
         MultivaluedMap<String, String> headers = new MultivaluedMapImpl();
         ContainerRequestUserRole creq =
                  new ContainerRequestUserRole("GET", new URI(HTTP_BACKUP_AGENT_PATH
                           + HTTPBackupAgent.Constants.OperationType.GET_DEFAULT_WORKSPACE_CONFIG), new URI(""), null,
                           new InputHeadersMap(headers));

         ByteArrayContainerResponseWriter responseWriter = new ByteArrayContainerResponseWriter();
         ContainerResponse cres = new ContainerResponse(responseWriter);
         handler.handleRequest(creq, cres);

         assertEquals(200, cres.getStatus());
         defWEntry = (WorkspaceEntry) getObject(WorkspaceEntry.class, responseWriter.getBody());
      }

      ArrayList<WorkspaceEntry> wsEntries = new ArrayList<WorkspaceEntry>();
      wsEntries.add(makeWorkspaceEntry(defWEntry, "db6backup", "ws", "jdbcjcr27"));
      wsEntries.add(makeWorkspaceEntry(defWEntry, "db6backup", "ws2", "jdbcjcr27"));
      RepositoryEntry rEntry = makeRepositoryEntry(defREntry, "db6backup", wsEntries);

      // Check the repository /db6backup.
      try
      {
         repositoryService.getRepository("db6backup");
         // ok
      }
      catch (Exception e)
      {
         fail("The repository /db6backup should be exists.");
      }

      // Restore
      {
         // Create JSON to WorkspaceEntry
         JsonGeneratorImpl generatorImpl = new JsonGeneratorImpl();
         JsonValue json = generatorImpl.createJsonObject(rEntry);

         // Execute restore
         MultivaluedMap<String, String> headers = new MultivaluedMapImpl();
         headers.putSingle("Content-Type", "application/json; charset=UTF-8");
         ContainerRequestUserRole creq =
                  new ContainerRequestUserRole("POST", new URI(HTTP_BACKUP_AGENT_PATH
                           + HTTPBackupAgent.Constants.OperationType.RESTORE_REPOSITORY_BACKUP_SET + "/"
                           + "true" + "?backup-set-path=" + backupSetPath),
                           new URI(""), new ByteArrayInputStream(json.toString().getBytes("UTF-8")),
                           new InputHeadersMap(headers));

         ByteArrayContainerResponseWriter responseWriter = new ByteArrayContainerResponseWriter();
         ContainerResponse cres = new ContainerResponse(responseWriter);
         handler.handleRequest(creq, cres);

         assertEquals(200, cres.getStatus());
      }

      waitRepositoryRestore("db6backup");

      // Get restore info
      {
         MultivaluedMap<String, String> headers = new MultivaluedMapImpl();
         ContainerRequestUserRole creq =
                  new ContainerRequestUserRole("GET", new URI(HTTP_BACKUP_AGENT_PATH
                           + HTTPBackupAgent.Constants.OperationType.CURRENT_RESTORE_INFO_ON_REPOSITORY + "/"
                           + "db6backup"), new URI(""), null, new InputHeadersMap(headers));

         ByteArrayContainerResponseWriter responseWriter = new ByteArrayContainerResponseWriter();
         ContainerResponse cres = new ContainerResponse(responseWriter);
         handler.handleRequest(creq, cres);

         assertEquals(200, cres.getStatus());

         DetailedInfo info = (DetailedInfo) getObject(DetailedInfo.class, responseWriter.getBody());

         assertNotNull(info);
         assertEquals(BackupManager.FULL_AND_INCREMENTAL, info.getBackupType().intValue());
View Full Code Here

                  new ContainerRequestUserRole("GET", new URI(HTTP_BACKUP_AGENT_PATH
                           + HTTPBackupAgent.Constants.OperationType.COMPLETED_BACKUPS_REPOSITORY_INFO), new URI(""),
                           null, new InputHeadersMap(headers));

         ByteArrayContainerResponseWriter responseWriter = new ByteArrayContainerResponseWriter();
         ContainerResponse cres = new ContainerResponse(responseWriter);
         handler.handleRequest(creq, cres);

         assertEquals(200, cres.getStatus());

         ShortInfoList infoList = (ShortInfoList) getObject(ShortInfoList.class, responseWriter.getBody());
         List<ShortInfo> list = new ArrayList<ShortInfo>(infoList.getBackups());

         ShortInfo info = getBackupInfo(list);
         assertNotNull(info);

         assertEquals(info.getRepositoryName(), "db6");

         id = info.getBackupId();

         for (RepositoryBackupChainLog bcl : backup.getRepositoryBackupsLogs())
         {
            if (bcl.getBackupId().equals(id))
            {
               backupSetPath = URLEncoder.encode(bcl.getBackupConfig().getBackupDir().getCanonicalPath(), "UTF-8");
               break;
            }
         }
      }

      // Getting default RepositoryEntry
      RepositoryEntry defREntry;
      {
         MultivaluedMap<String, String> headers = new MultivaluedMapImpl();
         ContainerRequestUserRole creq =
                  new ContainerRequestUserRole("GET", new URI(HTTP_BACKUP_AGENT_PATH
                           + HTTPBackupAgent.Constants.OperationType.GET_DEFAULT_REPOSITORY_CONFIG), new URI(""), null,
                           new InputHeadersMap(headers));

         ByteArrayContainerResponseWriter responseWriter = new ByteArrayContainerResponseWriter();
         ContainerResponse cres = new ContainerResponse(responseWriter);
         handler.handleRequest(creq, cres);

         assertEquals(200, cres.getStatus());
         defREntry = (RepositoryEntry) getObject(RepositoryEntry.class, responseWriter.getBody());
      }

      // Getting default WorkspaceEntry
      WorkspaceEntry defWEntry;
      {
         MultivaluedMap<String, String> headers = new MultivaluedMapImpl();
         ContainerRequestUserRole creq =
                  new ContainerRequestUserRole("GET", new URI(HTTP_BACKUP_AGENT_PATH
                           + HTTPBackupAgent.Constants.OperationType.GET_DEFAULT_WORKSPACE_CONFIG), new URI(""), null,
                           new InputHeadersMap(headers));

         ByteArrayContainerResponseWriter responseWriter = new ByteArrayContainerResponseWriter();
         ContainerResponse cres = new ContainerResponse(responseWriter);
         handler.handleRequest(creq, cres);

         assertEquals(200, cres.getStatus());
         defWEntry = (WorkspaceEntry) getObject(WorkspaceEntry.class, responseWriter.getBody());
      }

      ArrayList<WorkspaceEntry> wsEntries = new ArrayList<WorkspaceEntry>();
      wsEntries.add(makeWorkspaceEntry(defWEntry, "db6backup", "ws", "jdbcjcr27"));
      wsEntries.add(makeWorkspaceEntry(defWEntry, "db6backup", "ws2", "jdbcjcr27"));
      RepositoryEntry rEntry = makeRepositoryEntry(defREntry, "db6backup", wsEntries);

      removeRepositoryFully("db6backup");
      // Check the repository /db6backup.
      try
      {
         repositoryService.getRepository("db6backup");
         fail("The repository /db6backup should be not exists.");
      }
      catch (Exception e)
      {
         // ok
      }

      // Restore
      {
         // Create JSON to WorkspaceEntry
         JsonGeneratorImpl generatorImpl = new JsonGeneratorImpl();
         JsonValue json = generatorImpl.createJsonObject(rEntry);

         // Execute restore
         MultivaluedMap<String, String> headers = new MultivaluedMapImpl();
         headers.putSingle("Content-Type", "application/json; charset=UTF-8");
         ContainerRequestUserRole creq =
                  new ContainerRequestUserRole("POST", new URI(HTTP_BACKUP_AGENT_PATH
                           + HTTPBackupAgent.Constants.OperationType.RESTORE_REPOSITORY_BACKUP_SET + "/"
                           + "false" + "?backup-set-path=" + backupSetPath), new URI(""), new ByteArrayInputStream(json.toString()
                           .getBytes("UTF-8")), new InputHeadersMap(headers));

         ByteArrayContainerResponseWriter responseWriter = new ByteArrayContainerResponseWriter();
         ContainerResponse cres = new ContainerResponse(responseWriter);
         handler.handleRequest(creq, cres);

         assertEquals(200, cres.getStatus());
      }

      waitRepositoryRestore("db6backup");

      // Get restore info
      {
         MultivaluedMap<String, String> headers = new MultivaluedMapImpl();
         ContainerRequestUserRole creq =
                  new ContainerRequestUserRole("GET", new URI(HTTP_BACKUP_AGENT_PATH
                           + HTTPBackupAgent.Constants.OperationType.CURRENT_RESTORE_INFO_ON_REPOSITORY + "/"
                           + "db6backup"), new URI(""), null, new InputHeadersMap(headers));

         ByteArrayContainerResponseWriter responseWriter = new ByteArrayContainerResponseWriter();
         ContainerResponse cres = new ContainerResponse(responseWriter);
         handler.handleRequest(creq, cres);

         assertEquals(200, cres.getStatus());

         DetailedInfo info = (DetailedInfo) getObject(DetailedInfo.class, responseWriter.getBody());

         assertNotNull(info);
         assertEquals(BackupManager.FULL_AND_INCREMENTAL, info.getBackupType().intValue());
View Full Code Here

                  new ContainerRequestUserRole("GET", new URI(HTTP_BACKUP_AGENT_PATH
                           + HTTPBackupAgent.Constants.OperationType.COMPLETED_BACKUPS_REPOSITORY_INFO), new URI(""),
                           null, new InputHeadersMap(headers));

         ByteArrayContainerResponseWriter responseWriter = new ByteArrayContainerResponseWriter();
         ContainerResponse cres = new ContainerResponse(responseWriter);
         handler.handleRequest(creq, cres);

         assertEquals(200, cres.getStatus());

         ShortInfoList infoList = (ShortInfoList) getObject(ShortInfoList.class, responseWriter.getBody());
         List<ShortInfo> list = new ArrayList<ShortInfo>(infoList.getBackups());

         ShortInfo info = getBackupInfo(list);
         assertNotNull(info);

         assertEquals(info.getRepositoryName(), "db6");

         id = info.getBackupId();

         for (RepositoryBackupChainLog bcl : backup.getRepositoryBackupsLogs())
         {
            if (bcl.getBackupId().equals(id))
            {
               backupSetPath = URLEncoder.encode(bcl.getBackupConfig().getBackupDir().getCanonicalPath(), "UTF-8");
               break;
            }
         }
      }

      // Check the repository /db6.
      try
      {
         repositoryService.getRepository("db6");
         // ok
      }
      catch (Exception e)
      {
         fail("The repository /db6 should be exists.");
      }

      // Restore
      {
         // Execute restore
         MultivaluedMap<String, String> headers = new MultivaluedMapImpl();
         ContainerRequestUserRole creq =
                  new ContainerRequestUserRole("GET", new URI(HTTP_BACKUP_AGENT_PATH
                           + HTTPBackupAgent.Constants.OperationType.RESTORE_BACKUP_SET + "/" + "true"
                           + "?backup-set-path=" + backupSetPath), new URI(""), null, new InputHeadersMap(headers));

         ByteArrayContainerResponseWriter responseWriter = new ByteArrayContainerResponseWriter();
         ContainerResponse cres = new ContainerResponse(responseWriter);
         handler.handleRequest(creq, cres);

         assertEquals(200, cres.getStatus());
      }

      waitRepositoryRestore("db6");

      // Get restore info
      {
         MultivaluedMap<String, String> headers = new MultivaluedMapImpl();
         ContainerRequestUserRole creq =
                  new ContainerRequestUserRole("GET", new URI(HTTP_BACKUP_AGENT_PATH
                           + HTTPBackupAgent.Constants.OperationType.CURRENT_RESTORE_INFO_ON_REPOSITORY + "/" + "db6"),
                           new URI(""), null, new InputHeadersMap(headers));

         ByteArrayContainerResponseWriter responseWriter = new ByteArrayContainerResponseWriter();
         ContainerResponse cres = new ContainerResponse(responseWriter);
         handler.handleRequest(creq, cres);

         assertEquals(200, cres.getStatus());

         DetailedInfo info = (DetailedInfo) getObject(DetailedInfo.class, responseWriter.getBody());

         assertNotNull(info);
         assertEquals(BackupManager.FULL_AND_INCREMENTAL, info.getBackupType().intValue());
View Full Code Here

                  new ContainerRequestUserRole("GET", new URI(HTTP_BACKUP_AGENT_PATH
                           + HTTPBackupAgent.Constants.OperationType.COMPLETED_BACKUPS_REPOSITORY_INFO), new URI(""),
                           null, new InputHeadersMap(headers));

         ByteArrayContainerResponseWriter responseWriter = new ByteArrayContainerResponseWriter();
         ContainerResponse cres = new ContainerResponse(responseWriter);
         handler.handleRequest(creq, cres);

         assertEquals(200, cres.getStatus());

         ShortInfoList infoList = (ShortInfoList) getObject(ShortInfoList.class, responseWriter.getBody());
         List<ShortInfo> list = new ArrayList<ShortInfo>(infoList.getBackups());

         ShortInfo info = getBackupInfo(list);
         assertNotNull(info);

         assertEquals(info.getRepositoryName(), "db6");

         id = info.getBackupId();

         for (RepositoryBackupChainLog bcl : backup.getRepositoryBackupsLogs())
         {
            if (bcl.getBackupId().equals(id))
            {
               backupSetPath = URLEncoder.encode(bcl.getBackupConfig().getBackupDir().getCanonicalPath(), "UTF-8");
               break;
            }
         }
      }

      removeRepositoryFully("db6");
      // Check the repository /db6.
      try
      {
         repositoryService.getRepository("db6");
         fail("The repository /db6 should be not exists.");
      }
      catch (Exception e)
      {
         // ok
      }

      // Restore
      {
         // Execute restore
         MultivaluedMap<String, String> headers = new MultivaluedMapImpl();
         ContainerRequestUserRole creq =
                  new ContainerRequestUserRole("GET", new URI(HTTP_BACKUP_AGENT_PATH
                           + HTTPBackupAgent.Constants.OperationType.RESTORE_BACKUP_SET + "/" + "false"
                           + "?backup-set-path=" + backupSetPath), new URI(""), null, new InputHeadersMap(headers));

         ByteArrayContainerResponseWriter responseWriter = new ByteArrayContainerResponseWriter();
         ContainerResponse cres = new ContainerResponse(responseWriter);
         handler.handleRequest(creq, cres);

         assertEquals(200, cres.getStatus());
      }

      waitRepositoryRestore("db6");

      // Get restore info
      {
         MultivaluedMap<String, String> headers = new MultivaluedMapImpl();
         ContainerRequestUserRole creq =
                  new ContainerRequestUserRole("GET", new URI(HTTP_BACKUP_AGENT_PATH
                           + HTTPBackupAgent.Constants.OperationType.CURRENT_RESTORE_INFO_ON_REPOSITORY + "/" + "db6"),
                           new URI(""), null, new InputHeadersMap(headers));

         ByteArrayContainerResponseWriter responseWriter = new ByteArrayContainerResponseWriter();
         ContainerResponse cres = new ContainerResponse(responseWriter);
         handler.handleRequest(creq, cres);

         assertEquals(200, cres.getStatus());

         DetailedInfo info = (DetailedInfo) getObject(DetailedInfo.class, responseWriter.getBody());

         assertNotNull(info);
         assertEquals(BackupManager.FULL_AND_INCREMENTAL, info.getBackupType().intValue());
View Full Code Here

                  new ContainerRequestUserRole("GET", new URI(HTTP_BACKUP_AGENT_PATH
                           + HTTPBackupAgent.Constants.OperationType.CURRENT_RESTORE_INFO_ON_WS + "/" + repoName + "/"
                           + wsName), new URI(""), null, new InputHeadersMap(headers));

         ByteArrayContainerResponseWriter responseWriter = new ByteArrayContainerResponseWriter();
         ContainerResponse cres = new ContainerResponse(responseWriter);
         handler.handleRequest(creq, cres);

         assertEquals(200, cres.getStatus());

         DetailedInfo info = (DetailedInfo) getObject(DetailedInfo.class, responseWriter.getBody());

         if (info.getState().intValue() == JobWorkspaceRestore.RESTORE_SUCCESSFUL
                  || info.getState().intValue() == JobWorkspaceRestore.RESTORE_FAIL)
View Full Code Here

                  new ContainerRequestUserRole("GET", new URI(HTTP_BACKUP_AGENT_PATH
                           + HTTPBackupAgent.Constants.OperationType.CURRENT_RESTORE_INFO_ON_REPOSITORY + "/"
                           + repoName), new URI(""), null, new InputHeadersMap(headers));

         ByteArrayContainerResponseWriter responseWriter = new ByteArrayContainerResponseWriter();
         ContainerResponse cres = new ContainerResponse(responseWriter);
         handler.handleRequest(creq, cres);

         assertEquals(200, cres.getStatus());

         DetailedInfo info = (DetailedInfo) getObject(DetailedInfo.class, responseWriter.getBody());

         if (info.getState().intValue() == JobRepositoryRestore.REPOSITORY_RESTORE_SUCCESSFUL
                  || info.getState().intValue() == JobRepositoryRestore.REPOSITORY_RESTORE_FAIL)
View Full Code Here

TOP

Related Classes of org.exoplatform.services.rest.impl.ContainerResponse

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.