<commit_before>/*
Apache2 License Notice
Copyright 2017 <NAME>

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 adrestia;

import java.io.PrintWriter;
import java.lang.Double;
import java.util.HashMap;
import java.util.Map;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.embedded.LocalServerPort;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.junit4.SpringRunner;

/**
* Basic Object Tests against the Adrestia Server.
*/
@RunWith(SpringRunner.class)
@SpringBootTest(classes = Adrestia.class,
    webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@TestPropertySource(properties = {"management.port=5889"})
public class ObjectServerTest {
  @LocalServerPort
  private int port;

  @Value("${local.management.port}")
  private int mgtPort;

  @Autowired
  private TestRestTemplate testTemplate;

  // Test basic CRUD Functions for objects
  @Test
  public void testObjectCrudApi() throws Exception {
    String testSceneName = "AeselTestScene11";
    String testObjectName = "AeselTestObject11";
    String testObjectUrl = "/v1/scene/" + testSceneName + "/object/" + testObjectName;
    double tolerance = 0.00001;
    // Open up a file that we can write some test results to
    // Shouldn't be relied on for automated testing but good for debugging
    PrintWriter testLogger = new PrintWriter("logs/testObjectCrudApi.txt", "UTF-8");
    try {
      testLogger.println("Starting Test for Object CRUD API");
      // Create Test
      // Build a new Object
      testLogger.println("Create Test");
      double[] translation = {0.0, 0.0, 0.0};
      double[] rotationEuler = {0.0, 0.0, 0.0, 0.0};
      double[] scale = {1.0, 1.0, 1.0};
      String[] assets = {"TestAsset1", "TestAsset2"};
      ObjectDocument obj = new ObjectDocument("TestKey", "AeselTestObject11",
          "TestType", "TestSubtype", "TestOwner", "AeselTestScene11",
          translation, rotationEuler, scale, assets, null);

      // Post the Object to the endpoint
      ResponseEntity<Map> createResponse = this.testTemplate.postForEntity(
          "http://localhost:" + this.port + testObjectUrl, obj, Map.class);
      testLogger.println(createResponse.getStatusCode());
      // Read the response
      assert (createResponse.getStatusCode().is2xxSuccessful());
      // Validate the response
      Map crtRespBody = createResponse.getBody();
      testLogger.println("Create Response: " + crtRespBody.toString());
      testLogger.println("Key: " + crtRespBody.get("key"));
      assert (!(crtRespBody.get("key").toString().isEmpty()));

      // Get Test
      testLogger.println("Get Test");
      // Issue a get request for the object just created
      ResponseEntity<Map> getResponse = this.testTemplate.getForEntity(
          "http://localhost:" + this.port + testObjectUrl, Map.class);
      // Read the response
      assert (getResponse.getStatusCode().is2xxSuccessful());
      // Validate the response
      Map getRespBody = getResponse.getBody();
      testLogger.println("Get Response: " + getRespBody.toString());
      assert (getRespBody.get("type") == "TestType");

      // Update Test
      testLogger.println("Update Test");
      double[] translation2 = {1.0, 1.0, 1.0};
      double[] rotationEuler2 = {1.0, 1.0, 1.0, 45.0};
      double[] scale2 = {2.0, 2.0, 2.0};
      String[] assets2 = {"TestAsset3", "TestAsset4"};
      ObjectDocument obj2 = new ObjectDocument("TestKey", "AeselTestObject11",
          "TestType2", "TestSubtype2", "TestOwner2", "AeselTestScene11",
          translation2, rotationEuler2, scale2, assets2, null);
      // Post the Scene to the endpoint
      ResponseEntity<Map> updateResponse = this.testTemplate.postForEntity(
          "http://localhost:" + this.port + testObjectUrl, obj2, Map.class);
      // Read the response
      assert (updateResponse.getStatusCode().is2xxSuccessful());
      // Validate the response
      Map updRespBody = updateResponse.getBody();
      testLogger.println("Update Response: " + updRespBody.toString());

      // Run a secondary get test to validate the update
      testLogger.println("Get Test");
      // Issue a get request for the scene just updated
      ResponseEntity<Map> getResponse2 = this.testTemplate.getForEntity(
          "http://localhost:" + this.port + testObjectUrl, Map.class);
      // Read the response
      assert (getResponse2.getStatusCode().is2xxSuccessful());
      // Validate the response
      Map getRespBody2 = getResponse2.getBody();
      testLogger.println("Get Response: " + getRespBody2.toString());
      assert (getRespBody2.get("type") == "TestType");

      // Delete Test
      testLogger.println("Delete Test");
      // Delete the scene
      this.testTemplate.delete(
          "http://localhost:" + this.port + testObjectUrl, Map.class);

      // Run a tertiary get test to validate the update
      testLogger.println("Get Test");
      // Issue a get request for the scene just updated
      ResponseEntity<Map> getResponse3 = this.testTemplate.getForEntity(
          "http://localhost:" + this.port + testObjectUrl, Map.class);
      // Read the response
      testLogger.println("Delete Test Response Code");
      testLogger.println(getResponse3.getStatusCode());
      assert (getResponse3.getStatusCode().is4xxClientError());
    } catch (Exception e) {
      e.printStackTrace(testLogger);
      assert (false);
    } finally  {
      // Close the output text file
      testLogger.close();<commit_msg>Ensure use of .equals() for string comparison<commit_after>/*
Apache2 License Notice
Copyright 2017 <NAME>

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 adrestia;

import java.io.PrintWriter;
import java.lang.Double;
import java.util.HashMap;
import java.util.Map;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.embedded.LocalServerPort;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.junit4.SpringRunner;

/**
* Basic Object Tests against the Adrestia Server.
*/
@RunWith(SpringRunner.class)
@SpringBootTest(classes = Adrestia.class,
    webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@TestPropertySource(properties = {"management.port=5889"})
public class ObjectServerTest {
  @LocalServerPort
  private int port;

  @Value("${local.management.port}")
  private int mgtPort;

  @Autowired
  private TestRestTemplate testTemplate;

  // Test basic CRUD Functions for objects
  @Test
  public void testObjectCrudApi() throws Exception {
    String testSceneName = "AeselTestScene11";
    String testObjectName = "AeselTestObject11";
    String testObjectUrl = "/v1/scene/" + testSceneName + "/object/" + testObjectName;
    double tolerance = 0.00001;
    // Open up a file that we can write some test results to
    // Shouldn't be relied on for automated testing but good for debugging
    PrintWriter testLogger = new PrintWriter("logs/testObjectCrudApi.txt", "UTF-8");
    try {
      testLogger.println("Starting Test for Object CRUD API");
      // Create Test
      // Build a new Object
      testLogger.println("Create Test");
      double[] translation = {0.0, 0.0, 0.0};
      double[] rotationEuler = {0.0, 0.0, 0.0, 0.0};
      double[] scale = {1.0, 1.0, 1.0};
      String[] assets = {"TestAsset1", "TestAsset2"};
      ObjectDocument obj = new ObjectDocument("TestKey", "AeselTestObject11",
          "TestType", "TestSubtype", "TestOwner", "AeselTestScene11",
          translation, rotationEuler, scale, assets, null);

      // Post the Object to the endpoint
      ResponseEntity<Map> createResponse = this.testTemplate.postForEntity(
          "http://localhost:" + this.port + testObjectUrl, obj, Map.class);
      testLogger.println(createResponse.getStatusCode());
      // Read the response
      assert (createResponse.getStatusCode().is2xxSuccessful());
      // Validate the response
      Map crtRespBody = createResponse.getBody();
      testLogger.println("Create Response: " + crtRespBody.toString());
      testLogger.println("Key: " + crtRespBody.get("key"));
      assert (!(crtRespBody.get("key").toString().isEmpty()));

      // Get Test
      testLogger.println("Get Test");
      // Issue a get request for the object just created
      ResponseEntity<Map> getResponse = this.testTemplate.getForEntity(
          "http://localhost:" + this.port + testObjectUrl, Map.class);
      // Read the response
      assert (getResponse.getStatusCode().is2xxSuccessful());
      // Validate the response
      Map getRespBody = getResponse.getBody();
      testLogger.println("Get Response: " + getRespBody.toString());
      assert (getRespBody.get("type").equals("TestType"));

      // Update Test
      testLogger.println("Update Test");
      double[] translation2 = {1.0, 1.0, 1.0};
      double[] rotationEuler2 = {1.0, 1.0, 1.0, 45.0};
      double[] scale2 = {2.0, 2.0, 2.0};
      String[] assets2 = {"TestAsset3", "TestAsset4"};
      ObjectDocument obj2 = new ObjectDocument("TestKey", "AeselTestObject11",
          "TestType2", "TestSubtype2", "TestOwner2", "AeselTestScene11",
          translation2, rotationEuler2, scale2, assets2, null);
      // Post the Scene to the endpoint
      ResponseEntity<Map> updateResponse = this.testTemplate.postForEntity(
          "http://localhost:" + this.port + testObjectUrl, obj2, Map.class);
      // Read the response
      assert (updateResponse.getStatusCode().is2xxSuccessful());
      // Validate the response
      Map updRespBody = updateResponse.getBody();
      testLogger.println("Update Response: " + updRespBody.toString());

      // Run a secondary get test to validate the update
      testLogger.println("Get Test");
      // Issue a get request for the scene just updated
      ResponseEntity<Map> getResponse2 = this.testTemplate.getForEntity(
          "http://localhost:" + this.port + testObjectUrl, Map.class);
      // Read the response
      assert (getResponse2.getStatusCode().is2xxSuccessful());
      // Validate the response
      Map getRespBody2 = getResponse2.getBody();
      testLogger.println("Get Response: " + getRespBody2.toString());
      assert (getRespBody2.get("type").equals("TestType"));

      // Delete Test
      testLogger.println("Delete Test");
      // Delete the scene
      this.testTemplate.delete(
          "http://localhost:" + this.port + testObjectUrl, Map.class);

      // Run a tertiary get test to validate the update
      testLogger.println("Get Test");
      // Issue a get request for the scene just updated
      ResponseEntity<Map> getResponse3 = this.testTemplate.getForEntity(
          "http://localhost:" + this.port + testObjectUrl, Map.class);
      // Read the response
      testLogger.println("Delete Test Response Code");
      testLogger.println(getResponse3.getStatusCode());
      assert (getResponse3.getStatusCode().is4xxClientError());
    } catch (Exception e) {
      e.printStackTrace(testLogger);
      assert (false);
    } finally  {
      // Close the output text file
      testLogger.close();
{'fraction_non_alphanumeric': 0.11655722326454034, 'fraction_numerical': 0.01657285803627267, 'mean_word_length': 3.520494699646643, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1785336', 'n_tokens_mistral': 3630, 'n_tokens_neox': 3520, 'n_words': 987}