コード例 #1
0
  @Test
  public void test010_DeploySimpleApplicationTest() throws Exception {
    logger.info("Deploy an SpringBoot application");
    String binary = "spring-boot.jar";

    try {
      logger.info("Create " + binary + " application.");
      String jsonString =
          "{\"applicationName\":\"" + applicationName + "\", \"serverName\":\"" + release + "\"}";
      ResultActions resultats =
          mockMvc.perform(
              post("/application")
                  .session(session)
                  .contentType(MediaType.APPLICATION_JSON)
                  .content(jsonString));
      resultats.andExpect(status().isOk());

      // OPEN THE PORT
      jsonString =
          "{\"applicationName\":\""
              + applicationName
              + "\",\"portToOpen\":\"8080\",\"portNature\":\"web\"}";
      resultats =
          this.mockMvc.perform(
              post("/application/ports")
                  .session(session)
                  .contentType(MediaType.APPLICATION_JSON)
                  .content(jsonString));
      resultats.andExpect(status().isOk()).andDo(print());
    } catch (Exception e) {
      logger.error(e.getMessage());
    }

    ResultActions resultats =
        mockMvc
            .perform(
                MockMvcRequestBuilders.fileUpload("/application/" + applicationName + "/deploy")
                    .file(
                        downloadAndPrepareFileToDeploy(
                            binary,
                            "https://github.com/Treeptik/CloudUnit/releases/download/1.0/"
                                + binary))
                    .session(session)
                    .contentType(MediaType.MULTIPART_FORM_DATA))
            .andDo(print());
    resultats.andExpect(status().is2xxSuccessful());

    String urlToCall =
        "http://" + applicationName.toLowerCase() + "-johndoe-forward-8080.cloudunit.dev";
    logger.debug(urlToCall);
    int i = 0;
    String content = null;
    while (i++ < TestUtils.NB_ITERATION_MAX) {
      content = getUrlContentPage(urlToCall);
      logger.debug(content);
      Thread.sleep(1000);
      if (content == null || !content.contains("502")) {
        break;
      }
    }
    logger.debug(content);
    if (content != null) {
      Assert.assertTrue(content.contains("Greetings from Spring Boot!"));
    }
  }
コード例 #2
0
  @Test
  public void test020_DeployMysqlApplicationTest() throws Exception {
    logger.info("Deploy an Mysql SpringBoot application");
    String binary = "spring-boot-mysql.jar";

    // Create an application
    logger.info("Create " + binary + " application.");
    String jsonString =
        "{\"applicationName\":\"" + applicationName + "\", \"serverName\":\"" + release + "\"}";
    ResultActions resultats =
        mockMvc.perform(
            post("/application")
                .session(session)
                .contentType(MediaType.APPLICATION_JSON)
                .content(jsonString));
    resultats.andExpect(status().isOk());

    // Open the port 8080
    jsonString =
        "{\"applicationName\":\""
            + applicationName
            + "\",\"portToOpen\":\"8080\",\"portNature\":\"web\"}";
    resultats =
        this.mockMvc.perform(
            post("/application/ports")
                .session(session)
                .contentType(MediaType.APPLICATION_JSON)
                .content(jsonString));
    resultats.andExpect(status().isOk()).andDo(print());

    // Add a module MYSQL
    jsonString = "{\"applicationName\":\"" + applicationName + "\", \"imageName\":\"mysql-5-5\"}";
    resultats =
        mockMvc.perform(
            post("/module")
                .session(session)
                .contentType(MediaType.APPLICATION_JSON)
                .content(jsonString));
    resultats.andExpect(status().isOk());

    // Deploy the fat Jar
    resultats =
        mockMvc
            .perform(
                MockMvcRequestBuilders.fileUpload("/application/" + applicationName + "/deploy")
                    .file(
                        downloadAndPrepareFileToDeploy(
                            binary,
                            "https://github.com/Treeptik/CloudUnit/releases/download/1.0/"
                                + binary))
                    .session(session)
                    .contentType(MediaType.MULTIPART_FORM_DATA))
            .andDo(print());
    resultats.andExpect(status().is2xxSuccessful());
    String urlToCall =
        "http://" + applicationName.toLowerCase() + "-johndoe-forward-8080.cloudunit.dev";
    logger.debug(urlToCall);
    int i = 0;
    String content = null;
    // Wait for the deployment
    while (i++ < TestUtils.NB_ITERATION_MAX) {
      content = getUrlContentPage(urlToCall);
      logger.debug(content);
      Thread.sleep(1000);
      if (content == null || !content.contains("502")) {
        break;
      }
    }
    logger.debug(content);
    if (content != null) {
      Assert.assertTrue(content.contains("CloudUnit PaaS"));
    }

    String url2AddAnUser =
        "******"
            + applicationName.toLowerCase()
            + "-johndoe-forward-8080.cloudunit.dev/[email protected]&name=johndoe";

    // Add a module MYSQL
    resultats =
        mockMvc.perform(
            get(url2AddAnUser).session(session).contentType(MediaType.APPLICATION_JSON));
    resultats.andExpect(status().isOk());
    content = getUrlContentPage(url2AddAnUser);
    Assert.assertTrue(content.contains("User succesfully created!"));
  }