diff --git a/Dockerfile.integrationtest b/Dockerfile.integrationtest
new file mode 100644
index 0000000..abfafe0
--- /dev/null
+++ b/Dockerfile.integrationtest
@@ -0,0 +1,37 @@
+# ------------------------------------------------------------------------------
+# Copyright (C) 2023 European Spallation Source ERIC.
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+# ------------------------------------------------------------------------------
+
+FROM openjdk:11
+
+# apt clean is run automatically in debian-based images.
+RUN apt update && apt install -y wait-for-it
+# Run commands as user 'olog'
+RUN useradd -ms /bin/bash olog
+
+# deployment unit
+COPY /target/service-olog*.jar /olog-target/service-olog*.jar
+
+# code coverage
+COPY target/jacoco/jacocoagent.jar /olog-target/jacocoagent.jar
+
+RUN chown olog:olog /olog-target
+USER olog
+EXPOSE 8080
+EXPOSE 8181
+
+CMD ["java", "-jar", "/olog-target/service-olog*.jar", "--spring.config.name=application"]
diff --git a/README.md b/README.md
index ce045dc..9758dd0 100644
--- a/README.md
+++ b/README.md
@@ -67,6 +67,27 @@ backends.
* Build the image: `docker-compose build`
* Run the containers: `docker-compose up`
+### Integration tests with Docker containers
+
+Purpose is to have integration tests for Olog API with Docker.
+
+See `src/test/java` and package
+* `org.phoebus.olog.docker`
+
+Integration tests start docker containers for Olog, Elasticsearch and MongoDB, and run http requests (GET) and curl commands (POST, PUT, DELETE) towards the application to test behavior (read, list, query, create, update, remove) and replies are received and checked if content is as expected.
+
+There are tests for properties, tags, logbooks and logs separately and in combination.
+
+Integration tests can be run in IDE and via Maven.
+
+```
+mvn failsafe:integration-test -DskipITs=false -Pintegrationtest-docker
+```
+
+See
+* [How to run Integration test with Docker](src/test/resources/INTEGRATIONTEST_DOCKER_RUN.md)
+* [Tutorial for Integration test with Docker](src/test/resources/INTEGRATIONTEST_DOCKER_TUTORIAL.md)
+
### Release Olog Server binaries to maven central
The Phoebus Olog service uses the maven release plugin to prepare the publish the olog server binaries to maven central
diff --git a/docker-compose-integrationtest.yml b/docker-compose-integrationtest.yml
new file mode 100644
index 0000000..799f4e8
--- /dev/null
+++ b/docker-compose-integrationtest.yml
@@ -0,0 +1,63 @@
+# Use the default network olog_default.
+version: "3.7"
+services:
+ olog:
+ build:
+ context: .
+ dockerfile: Dockerfile.integrationtest
+ ports:
+ - "8080:8080"
+ - "8181:8181"
+ depends_on:
+ - mongo
+ - elastic
+ # Ensure that the elastic server is up before starting olog.
+ environment:
+ ldap.enabled: "false"
+ embedded_ldap.enabled: "false"
+ demo_auth.enabled: "true"
+ skipITCoverage: "true"
+ command: >
+ /bin/bash -c "
+ while ! curl -s -f elastic:9200/_cluster/health?wait_for_status=yellow;
+ do
+ echo Waiting for Elasticsearch;
+ sleep 1;
+ done;
+ if [ ${skipITCoverage} == false ]; then
+ export JAVA_TOOL_OPTIONS=-javaagent:/olog-target/jacocoagent.jar=destfile=/olog-target/jacoco.exec,output=file,append=false
+ fi
+ java -jar /olog-target/service-olog*.jar --spring.config.name=application-docker
+ "
+
+ mongo:
+ image: mongo
+ ports:
+ - 27017:27017
+ volumes:
+ - olog-mongodata:/etc/mongo
+
+ elastic:
+ image: elasticsearch:8.2.3
+ environment:
+ cluster.name: elasticsearch
+ bootstrap.memory_lock: "true"
+ discovery.type: single-node
+ ES_JAVA_OPTS: "-Xms512m -Xmx512m"
+ xpack.security.enabled: "false"
+ xpack.security.http.ssl.enabled: "false"
+ ports:
+ - 9200:9200
+ volumes:
+ - olog-esdata:/usr/share/elasticsearch/data
+ ulimits:
+ memlock:
+ soft: -1
+ hard: -1
+
+# Configure persistent storage for mongo and elastic.
+volumes:
+ olog-esdata:
+ driver: local
+ olog-mongodata:
+ driver: local
diff --git a/pom.xml b/pom.xml
index ebe4106..415af56 100644
--- a/pom.xml
+++ b/pom.xml
@@ -56,6 +56,9 @@
8.2.0
1.18.16
5.8.2
+ true
+ true
+ true
@@ -195,6 +198,12 @@
2.2.220
runtime
+
+ org.jacoco
+ org.jacoco.agent
+ 0.8.10
+ runtime
+
org.junit.jupiter
@@ -207,7 +216,7 @@
org.testcontainers
junit-jupiter
- 1.17.5
+ 1.19.3
test
@@ -245,6 +254,18 @@
maven-surefire-plugin
3.0.0-M7
+
+
+ org.apache.maven.plugins
+ maven-failsafe-plugin
+ 3.2.2
+
+ ${skipITs}
+
+ **/*IT.java
+
+
+
org.apache.maven.plugins
maven-compiler-plugin
@@ -255,6 +276,72 @@
${project.build.sourceEncoding}
+
+ org.apache.maven.plugins
+ maven-dependency-plugin
+
+
+ copy
+ package
+
+ copy
+
+
+
+
+ org.jacoco
+ org.jacoco.agent
+ runtime
+ ${project.build.directory}/jacoco
+ jacocoagent.jar
+
+
+
+
+
+
+
+ org.jacoco
+ jacoco-maven-plugin
+ 0.8.10
+
+
+
+ prepare-agent
+
+
+
+ merge
+ verify
+
+ merge
+
+
+
+
+ ${project.build.directory}
+
+ jacoco*.exec
+
+
+
+ ${project.build.directory}/site/jacoco/jacoco.exec
+
+
+
+ report
+
+ verify
+
+ report
+
+
+ ${project.build.directory}/site/jacoco/jacoco.exec
+ ${project.build.directory}/site/jacoco
+
+
+
+
org.springframework.boot
spring-boot-maven-plugin
@@ -373,6 +460,25 @@
+
+
+ integrationtest-docker
+
+
+
+ org.apache.maven.plugins
+ maven-failsafe-plugin
+ 3.2.2
+
+ ${skipITs}
+
+ **/docker/*IT.java
+
+
+
+
+
+
diff --git a/src/main/java/org/phoebus/olog/Application.java b/src/main/java/org/phoebus/olog/Application.java
index db963ce..c96e261 100644
--- a/src/main/java/org/phoebus/olog/Application.java
+++ b/src/main/java/org/phoebus/olog/Application.java
@@ -1,31 +1,16 @@
package org.phoebus.olog;
-import co.elastic.clients.elasticsearch.ElasticsearchClient;
-import org.apache.catalina.connector.Connector;
-import org.apache.coyote.http11.AbstractHttp11Protocol;
import org.phoebus.olog.notification.LogEntryNotifier;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
-import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
-import org.springframework.boot.web.embedded.tomcat.TomcatConnectorCustomizer;
-import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory;
-import org.springframework.boot.web.servlet.server.ServletWebServerFactory;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.core.task.TaskExecutor;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
-import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.util.FileCopyUtils;
-import org.springframework.web.method.support.HandlerMethodArgumentResolver;
-import org.springframework.web.servlet.config.annotation.CorsRegistry;
-import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
-import org.springframework.web.servlet.mvc.method.annotation.PrincipalMethodArgumentResolver;
-import javax.annotation.PostConstruct;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
@@ -57,7 +42,7 @@ public class Application {
private long propertyProvidersTimeout;
public static void main(String[] args) {
- logger.info("Starting Olog Service");
+ logger.log(Level.INFO, TextUtil.OLOG_STARTING);
configureTruststore();
ConfigurableApplicationContext olog = SpringApplication.run(Application.class, args);
}
@@ -76,7 +61,7 @@ private static void configureTruststore() {
tempFile.deleteOnExit();
System.setProperty("javax.net.ssl.trustStore", tempFile.getAbsolutePath());
} catch (IOException e) {
- logger.log(Level.SEVERE, "failed to configure olog truststore", e);
+ logger.log(Level.SEVERE, TextUtil.OLOG_FAILED_CONFIGURE_TRUSTSTORE, e);
}
}
if (System.getProperty("javax.net.ssl.trustStorePassword") == null) {
diff --git a/src/main/java/org/phoebus/olog/AttachmentRepository.java b/src/main/java/org/phoebus/olog/AttachmentRepository.java
index 9455312..6315908 100644
--- a/src/main/java/org/phoebus/olog/AttachmentRepository.java
+++ b/src/main/java/org/phoebus/olog/AttachmentRepository.java
@@ -19,6 +19,7 @@
import org.springframework.stereotype.Repository;
import java.io.IOException;
+import java.text.MessageFormat;
import java.util.Optional;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -63,7 +64,7 @@ public S save(S entity) {
return entity;
} catch (IOException e) {
Logger.getLogger(AttachmentRepository.class.getName())
- .log(Level.WARNING, String.format("Unable to persist attachment %s", entity.getFilename()), e);
+ .log(Level.WARNING, MessageFormat.format(TextUtil.ATTACHMENT_NOT_PERSISTED, entity.getFilename()), e);
}
return null;
}
diff --git a/src/main/java/org/phoebus/olog/AttachmentResource.java b/src/main/java/org/phoebus/olog/AttachmentResource.java
index 9fbe552..77ca416 100644
--- a/src/main/java/org/phoebus/olog/AttachmentResource.java
+++ b/src/main/java/org/phoebus/olog/AttachmentResource.java
@@ -14,7 +14,6 @@
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
-import org.springframework.util.MultiValueMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
@@ -23,10 +22,10 @@
import static org.phoebus.olog.OlogResourceDescriptors.ATTACHMENT_URI;
import java.io.IOException;
+import java.text.MessageFormat;
import java.util.Optional;
import java.util.logging.Level;
import java.util.logging.Logger;
-import java.util.stream.Collectors;
/**
* Resource for handling the requests to ../attachment
@@ -51,12 +50,11 @@ public class AttachmentResource
*/
@GetMapping("{attachmentId}")
public ResponseEntity getAttachment(@PathVariable String attachmentId) {
- log.log(Level.INFO, "Requesting attachment " + attachmentId);
+ log.log(Level.INFO, () -> MessageFormat.format(TextUtil.ATTACHMENT_REQUEST, attachmentId));
Optional attachment = attachmentRepository.findById(attachmentId);
- if(attachment.isPresent()){
+ if (attachment.isPresent()) {
InputStreamResource resource;
- try
- {
+ try {
resource = new InputStreamResource(attachment.get().getAttachment().getInputStream());
ContentDisposition contentDisposition = ContentDisposition.builder("attachment")
.filename(attachment.get().getFilename())
@@ -68,16 +66,14 @@ public ResponseEntity getAttachment(@PathVariable String attachmentId)
httpHeaders.setContentType(mediaType);
}
return new ResponseEntity<>(resource, httpHeaders, HttpStatus.OK);
- }
- catch (IOException e) {
+ } catch (IOException e) {
Logger.getLogger(LogResource.class.getName())
- .log(Level.SEVERE, "Unable to retrieve attachment with id: " + attachmentId, e);
+ .log(Level.SEVERE, MessageFormat.format(TextUtil.ATTACHMENT_NOT_RETRIEVED, attachmentId), e);
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
}
- }
- else{
+ } else {
Logger.getLogger(LogResource.class.getName())
- .log(Level.WARNING, "Attachment with id " + attachmentId + " not found");
+ .log(Level.WARNING, () -> MessageFormat.format(TextUtil.ATTACHMENT_NOT_FOUND, attachmentId));
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
}
}
diff --git a/src/main/java/org/phoebus/olog/AuthorizationService.java b/src/main/java/org/phoebus/olog/AuthorizationService.java
index df67438..c8631a1 100644
--- a/src/main/java/org/phoebus/olog/AuthorizationService.java
+++ b/src/main/java/org/phoebus/olog/AuthorizationService.java
@@ -30,41 +30,41 @@ public class AuthorizationService {
@Value("${admin-groups:olog-admins}")
void initializeAdminRoles(String groups)
{
- this.admin_groups = Arrays.asList(groups.split(",")).stream().map(g -> {
- return "ROLE_" + g.trim().toUpperCase();
- }).collect(Collectors.toList());
+ this.admin_groups = Arrays.asList(groups.split(",")).stream().map(g ->
+ "ROLE_" + g.trim().toUpperCase()
+ ).collect(Collectors.toList());
}
@Value("${channel-groups:olog-logs}")
void initializeChannelModRoles(String groups)
{
- this.log_groups = Arrays.asList(groups.split(",")).stream().map(g -> {
- return "ROLE_" + g.trim().toUpperCase();
- }).collect(Collectors.toList());
+ this.log_groups = Arrays.asList(groups.split(",")).stream().map(g ->
+ "ROLE_" + g.trim().toUpperCase()
+ ).collect(Collectors.toList());
}
@Value("${tag-groups:olog-tags}")
void initializeTagRoles(String groups)
{
- this.tag_groups = Arrays.asList(groups.split(",")).stream().map(g -> {
- return "ROLE_" + g.trim().toUpperCase();
- }).collect(Collectors.toList());
+ this.tag_groups = Arrays.asList(groups.split(",")).stream().map(g ->
+ "ROLE_" + g.trim().toUpperCase()
+ ).collect(Collectors.toList());
}
@Value("${property-groups:olog-logbooks}")
void initializeLogbookRoles(String groups)
{
- this.logbook_groups = Arrays.asList(groups.split(",")).stream().map(g -> {
- return "ROLE_" + g.trim().toUpperCase();
- }).collect(Collectors.toList());
+ this.logbook_groups = Arrays.asList(groups.split(",")).stream().map(g ->
+ "ROLE_" + g.trim().toUpperCase()
+ ).collect(Collectors.toList());
}
@Value("${property-groups:olog-properties}")
void initializePropertyRoles(String groups)
{
- this.property_groups = Arrays.asList(groups.split(",")).stream().map(g -> {
- return "ROLE_" + g.trim().toUpperCase();
- }).collect(Collectors.toList());
+ this.property_groups = Arrays.asList(groups.split(",")).stream().map(g ->
+ "ROLE_" + g.trim().toUpperCase()
+ ).collect(Collectors.toList());
}
public enum ROLES
diff --git a/src/main/java/org/phoebus/olog/ContentTypeResolver.java b/src/main/java/org/phoebus/olog/ContentTypeResolver.java
index 190e1f7..cdf682d 100644
--- a/src/main/java/org/phoebus/olog/ContentTypeResolver.java
+++ b/src/main/java/org/phoebus/olog/ContentTypeResolver.java
@@ -23,6 +23,7 @@
import java.io.File;
import java.nio.file.Path;
+import java.text.MessageFormat;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -56,7 +57,7 @@ public static MediaType determineMediaType(String fileName){
}
catch(Exception e){
Logger.getLogger(ContentTypeResolver.class.getName())
- .log(Level.WARNING, "Unable to determine content type from file name {0}", fileName);
+ .log(Level.WARNING, MessageFormat.format(TextUtil.CONTENT_TYPE_NOT_DETERMINED, fileName));
return null;
}
}
diff --git a/src/main/java/org/phoebus/olog/ElasticConfig.java b/src/main/java/org/phoebus/olog/ElasticConfig.java
index 3a40164..e06f683 100644
--- a/src/main/java/org/phoebus/olog/ElasticConfig.java
+++ b/src/main/java/org/phoebus/olog/ElasticConfig.java
@@ -13,7 +13,6 @@
import co.elastic.clients.transport.rest_client.RestClientTransport;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
-import java.util.concurrent.TimeUnit;
import org.apache.http.HttpHost;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestClientBuilder;
@@ -29,6 +28,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
+import java.text.MessageFormat;
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.logging.Level;
@@ -103,7 +103,7 @@ private CreateIndexRequest.Builder withTimeouts(CreateIndexRequest.Builder build
}
private void logCreateIndexRequest(CreateIndexRequest request) {
- logger.log(Level.INFO, String.format(
+ logger.log(Level.INFO, () -> String.format(
"CreateIndexRequest: " +
"index: %s, " +
"timeout: %s, " +
@@ -119,7 +119,7 @@ private void logCreateIndexRequest(CreateIndexRequest request) {
public ElasticsearchClient getClient() {
if (client == null) {
// Create the low-level client
- logger.info(String.format("Creating HTTP client with " +
+ logger.log(Level.INFO, () -> String.format("Creating HTTP client with " +
"host %s, " +
"port %s, " +
"protocol %s, " +
@@ -176,10 +176,10 @@ void elasticIndexValidation(ElasticsearchClient client) {
CreateIndexResponse result = client.indices().create(
request
);
- logger.info("Created index: " + ES_SEQ_INDEX + " : acknowledged " + result.acknowledged());
+ logger.log(Level.INFO, () -> MessageFormat.format(TextUtil.ELASTIC_CREATED_INDEX_ACKNOWLEDGED, ES_SEQ_INDEX, result.acknowledged()));
}
} catch (IOException e) {
- logger.log(Level.WARNING, "Failed to create index " + ES_SEQ_INDEX, e);
+ logger.log(Level.WARNING, MessageFormat.format(TextUtil.ELASTIC_FAILED_TO_CREATE_INDEX, ES_SEQ_INDEX), e);
}
// Olog Logbook Index
@@ -191,10 +191,10 @@ void elasticIndexValidation(ElasticsearchClient client) {
);
logCreateIndexRequest(request);
CreateIndexResponse result = client.indices().create(request);
- logger.info("Created index: " + ES_LOGBOOK_INDEX + " : acknowledged " + result.acknowledged());
+ logger.log(Level.INFO, () -> MessageFormat.format(TextUtil.ELASTIC_CREATED_INDEX_ACKNOWLEDGED, ES_LOGBOOK_INDEX, result.acknowledged()));
}
} catch (IOException e) {
- logger.log(Level.WARNING, "Failed to create index " + ES_LOGBOOK_INDEX, e);
+ logger.log(Level.WARNING, MessageFormat.format(TextUtil.ELASTIC_FAILED_TO_CREATE_INDEX, ES_LOGBOOK_INDEX), e);
}
// Olog Tag Index
@@ -206,10 +206,10 @@ void elasticIndexValidation(ElasticsearchClient client) {
);
logCreateIndexRequest(request);
CreateIndexResponse result = client.indices().create(request);
- logger.info("Created index: " + ES_TAG_INDEX + " : acknowledged " + result.acknowledged());
+ logger.log(Level.INFO, () -> MessageFormat.format(TextUtil.ELASTIC_CREATED_INDEX_ACKNOWLEDGED, ES_TAG_INDEX, result.acknowledged()));
}
} catch (IOException e) {
- logger.log(Level.WARNING, "Failed to create index " + ES_TAG_INDEX, e);
+ logger.log(Level.WARNING, MessageFormat.format(TextUtil.ELASTIC_FAILED_TO_CREATE_INDEX, ES_TAG_INDEX), e);
}
// Olog Property Index
@@ -221,10 +221,10 @@ void elasticIndexValidation(ElasticsearchClient client) {
);
logCreateIndexRequest(request);
CreateIndexResponse result = client.indices().create(request);
- logger.info("Created index: " + ES_PROPERTY_INDEX + " : acknowledged " + result.acknowledged());
+ logger.log(Level.INFO, () -> MessageFormat.format(TextUtil.ELASTIC_CREATED_INDEX_ACKNOWLEDGED, ES_PROPERTY_INDEX, result.acknowledged()));
}
} catch (IOException e) {
- logger.log(Level.WARNING, "Failed to create index " + ES_PROPERTY_INDEX, e);
+ logger.log(Level.WARNING, MessageFormat.format(TextUtil.ELASTIC_FAILED_TO_CREATE_INDEX, ES_PROPERTY_INDEX), e);
}
// Olog Log Template
@@ -236,10 +236,10 @@ void elasticIndexValidation(ElasticsearchClient client) {
);
logCreateIndexRequest(request);
CreateIndexResponse result = client.indices().create(request);
- logger.info("Created index: " + ES_LOG_INDEX + " : acknowledged " + result.acknowledged());
+ logger.log(Level.INFO, () -> MessageFormat.format(TextUtil.ELASTIC_CREATED_INDEX_ACKNOWLEDGED, ES_LOG_INDEX, result.acknowledged()));
}
} catch (IOException e) {
- logger.log(Level.WARNING, "Failed to create index " + ES_LOG_INDEX, e);
+ logger.log(Level.WARNING, MessageFormat.format(TextUtil.ELASTIC_FAILED_TO_CREATE_INDEX, ES_LOG_INDEX), e);
}
// Olog Archived Log Template
try (InputStream is = ElasticConfig.class.getResourceAsStream("/log_entry_mapping.json")) {
@@ -250,10 +250,10 @@ void elasticIndexValidation(ElasticsearchClient client) {
);
logCreateIndexRequest(request);
CreateIndexResponse result = client.indices().create(request);
- logger.info("Created index: " + "archived_" + ES_LOG_ARCHIVE_INDEX + " : acknowledged " + result.acknowledged());
+ logger.log(Level.INFO, () -> MessageFormat.format(TextUtil.ELASTIC_CREATED_INDEX_ACKNOWLEDGED, ES_LOG_ARCHIVE_INDEX, result.acknowledged()));
}
} catch (IOException e) {
- logger.log(Level.WARNING, "Failed to create index " + ES_LOG_ARCHIVE_INDEX, e);
+ logger.log(Level.WARNING, MessageFormat.format(TextUtil.ELASTIC_FAILED_TO_CREATE_INDEX, ES_LOG_ARCHIVE_INDEX), e);
}
}
@@ -286,11 +286,11 @@ private void elasticIndexInitialization(ElasticsearchClient indexClient) {
IndexResponse response = client.index(indexRequest);
}
} catch (IOException e) {
- logger.log(Level.WARNING, "Failed to initialize logbook : " +logbook.getName(), e);
+ logger.log(Level.WARNING, MessageFormat.format(TextUtil.ELASTIC_FAILED_TO_INITIALIZE_LOGBOOK, logbook.getName()), e);
}
});
} catch (IOException ex) {
- logger.log(Level.WARNING, "Failed to initialize logbooks ", ex);
+ logger.log(Level.WARNING, TextUtil.ELASTIC_FAILED_TO_INITIALIZE_LOGBOOKS, ex);
}
// Setup the default tags
@@ -315,11 +315,11 @@ private void elasticIndexInitialization(ElasticsearchClient indexClient) {
IndexResponse response = client.index(indexRequest);
}
} catch (IOException e) {
- logger.log(Level.WARNING, "Failed to initialize tag : " +tag.getName(), e);
+ logger.log(Level.WARNING, MessageFormat.format(TextUtil.ELASTIC_FAILED_TO_INITIALIZE_TAG, tag.getName()), e);
}
});
} catch (IOException ex) {
- logger.log(Level.WARNING, "Failed to initialize tag ", ex);
+ logger.log(Level.WARNING, TextUtil.ELASTIC_FAILED_TO_INITIALIZE_TAGS, ex);
}
// Setup the default properties
@@ -344,11 +344,11 @@ private void elasticIndexInitialization(ElasticsearchClient indexClient) {
IndexResponse response = client.index(indexRequest);
}
} catch (IOException e) {
- logger.log(Level.WARNING, "Failed to initialize property : " +property.getName(), e);
+ logger.log(Level.WARNING, MessageFormat.format(TextUtil.ELASTIC_FAILED_TO_INITIALIZE_PROPERTY, property.getName()), e);
}
});
} catch (IOException ex) {
- logger.log(Level.WARNING, "Failed to initialize property ", ex);
+ logger.log(Level.WARNING, TextUtil.ELASTIC_FAILED_TO_INITIALIZE_PROPERTIES, ex);
}
}
}
\ No newline at end of file
diff --git a/src/main/java/org/phoebus/olog/HelpResource.java b/src/main/java/org/phoebus/olog/HelpResource.java
index f6bab93..0dd8390 100644
--- a/src/main/java/org/phoebus/olog/HelpResource.java
+++ b/src/main/java/org/phoebus/olog/HelpResource.java
@@ -33,6 +33,7 @@
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
+import java.text.MessageFormat;
import java.util.Locale;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -70,18 +71,18 @@ public String getHelpContent(@RequestParam(name = "lang", required = false) Stri
HttpServletRequest request) {
String language = determineLang(lang, request);
String content;
- logger.log(Level.INFO, "Requesting " + what + " for language=" + language);
+ logger.log(Level.INFO, () -> MessageFormat.format(TextUtil.HELP_REQUEST_WHAT_FOR_LANGUAGE, language));
InputStream inputStream;
try {
inputStream = getClass().getResourceAsStream("/static/" + what + "_" + language + ".html");
return readInputStream(inputStream);
} catch (Exception e) {
- logger.log(Level.SEVERE, "Unable to read " + what + " resource for language=" + language + ", defaulting to 'en'");
+ logger.log(Level.SEVERE, () -> MessageFormat.format(TextUtil.HELP_UNABLE_READ_FOR_LANGUAGE_DEFAULT, what, language));
try {
inputStream = getClass().getResourceAsStream("/static/" + what + "_en.html");
return readInputStream(inputStream);
} catch (Exception ioException) {
- logger.log(Level.SEVERE, "Unable to read find resource " + what + "_en.html");
+ logger.log(Level.SEVERE, () -> MessageFormat.format(TextUtil.HELP_UNABLE_FIND_RESOURCE, what));
throw new ResponseStatusException(HttpStatus.NOT_FOUND);
}
}
diff --git a/src/main/java/org/phoebus/olog/InfoResource.java b/src/main/java/org/phoebus/olog/InfoResource.java
index d9128ca..e7d82e3 100644
--- a/src/main/java/org/phoebus/olog/InfoResource.java
+++ b/src/main/java/org/phoebus/olog/InfoResource.java
@@ -16,6 +16,7 @@
import org.springframework.web.bind.annotation.RestController;
import java.io.IOException;
+import java.text.MessageFormat;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.logging.Level;
@@ -48,10 +49,10 @@ public class InfoResource
@Value("${spring.servlet.multipart.max-request-size:50MB}")
private String maxRequestSize;
- private final static ObjectMapper objectMapper = new ObjectMapper().enable(SerializationFeature.INDENT_OUTPUT);
+ private static final ObjectMapper objectMapper = new ObjectMapper().enable(SerializationFeature.INDENT_OUTPUT);
/**
- *
+ *
* @return Information about the Olog service
*/
@GetMapping
@@ -73,8 +74,8 @@ public String info() {
elasticInfo.put("elasticHost", host);
elasticInfo.put("elasticPort", String.valueOf(port));
} catch (IOException e) {
- Application.logger.log(Level.WARNING, "Failed to create Olog service info resource.", e);
- elasticInfo.put("status", "Failed to connect to elastic " + e.getLocalizedMessage());
+ Application.logger.log(Level.WARNING, TextUtil.OLOG_FAILED_CREATE_SERVICE, e);
+ elasticInfo.put("status", MessageFormat.format(TextUtil.ELASTIC_FAILED_TO_CONNECT, e.getLocalizedMessage()));
}
ologServiceInfo.put("elastic", elasticInfo);
ologServiceInfo.put("mongoDB", mongoClient.getClusterDescription().getShortDescription());
@@ -89,8 +90,8 @@ public String info() {
try {
return objectMapper.writeValueAsString(ologServiceInfo);
} catch (JsonProcessingException e) {
- Application.logger.log(Level.WARNING, "Failed to create Olog service info resource.", e);
- return "Failed to gather Olog service info";
+ Application.logger.log(Level.WARNING, TextUtil.OLOG_FAILED_CREATE_SERVICE, e);
+ return TextUtil.OLOG_FAILED_CREATE_SERVICE;
}
}
}
diff --git a/src/main/java/org/phoebus/olog/LogEntryValidator.java b/src/main/java/org/phoebus/olog/LogEntryValidator.java
index 3827f39..a9b0eb3 100644
--- a/src/main/java/org/phoebus/olog/LogEntryValidator.java
+++ b/src/main/java/org/phoebus/olog/LogEntryValidator.java
@@ -25,6 +25,7 @@
import org.springframework.validation.Errors;
import org.springframework.validation.Validator;
+import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
@@ -56,7 +57,7 @@ public void validate(Object object, Errors errors){
Log log = (Log)object;
if(log.getTitle() == null || log.getTitle().isEmpty()){
- logger.log(Level.INFO, "Log title empty.");
+ logger.log(Level.INFO, TextUtil.LOG_NOT_TITLE);
errors.rejectValue("logbooks", "no.title");
}
@@ -65,13 +66,13 @@ public void validate(Object object, Errors errors){
Set logbooks = log.getLogbooks();
if(logbooks.isEmpty()){
- logger.log(Level.INFO, "No logbooks specified.");
+ logger.log(Level.INFO, TextUtil.LOGBOOKS_NOT_SPECIFIED);
errors.rejectValue("logbooks", "no.logbooks");
}
for(Logbook logbook : log.getLogbooks()){
if(!existingLogbookNames.contains(logbook.getName())){
- logger.log(Level.INFO, "Logbook '" + logbook.getName() + "' is invalid.");
+ logger.log(Level.INFO, () -> MessageFormat.format(TextUtil.LOGBOOK_INVALID, logbook.getName()));
errors.rejectValue("logbooks", "invalid.logbooks");
}
}
@@ -80,7 +81,7 @@ public void validate(Object object, Errors errors){
tagRepository.findAll().forEach(t -> existingTagNames.add(t.getName()));
for(Tag tag : log.getTags()){
if(!existingTagNames.contains(tag.getName())){
- logger.log(Level.INFO, "Tag '" + tag.getName() + "' is invalid.");
+ logger.log(Level.INFO, () -> MessageFormat.format(TextUtil.TAG_INVALID, tag.getName()));
errors.rejectValue("tags", "invalid.tags");
}
}
diff --git a/src/main/java/org/phoebus/olog/LogRepository.java b/src/main/java/org/phoebus/olog/LogRepository.java
index 3d2c3bd..7e20d3c 100644
--- a/src/main/java/org/phoebus/olog/LogRepository.java
+++ b/src/main/java/org/phoebus/olog/LogRepository.java
@@ -23,7 +23,6 @@
import co.elastic.clients.elasticsearch.core.SearchResponse;
import co.elastic.clients.elasticsearch.core.mget.MultiGetResponseItem;
import co.elastic.clients.elasticsearch.core.search.Hit;
-import org.apache.logging.log4j.util.Strings;
import org.phoebus.olog.entity.Attachment;
import org.phoebus.olog.entity.Log;
import org.phoebus.olog.entity.Log.LogBuilder;
@@ -38,6 +37,7 @@
import org.springframework.web.server.ResponseStatusException;
import java.io.IOException;
+import java.text.MessageFormat;
import java.time.Instant;
import java.util.ArrayList;
import java.util.HashSet;
@@ -78,9 +78,9 @@ public S save(S log) {
LogBuilder validatedLog = LogBuilder.createLog(log).id(id).createDate(Instant.now());
if (log.getAttachments() != null && !log.getAttachments().isEmpty()) {
Set createdAttachments = new HashSet<>();
- log.getAttachments().stream().filter(attachment -> attachment.getAttachment() != null).forEach(attachment -> {
- createdAttachments.add(attachmentRepository.save(attachment));
- });
+ log.getAttachments().stream().filter(attachment -> attachment.getAttachment() != null).forEach(attachment ->
+ createdAttachments.add(attachmentRepository.save(attachment))
+ );
validatedLog = validatedLog.setAttachments(createdAttachments);
}
@@ -103,8 +103,9 @@ public S save(S log) {
return (S) resp.source();
}
} catch (Exception e) {
- logger.log(Level.SEVERE, "Failed to save log entry: " + log, e);
- throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, "Failed to save log entry: " + log);
+ String message = MessageFormat.format(TextUtil.LOG_NOT_SAVED, log);
+ logger.log(Level.SEVERE, message, e);
+ throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, message);
}
return null;
}
@@ -112,9 +113,9 @@ public S save(S log) {
@Override
public Iterable saveAll(Iterable logs) {
List createdLogs = new ArrayList<>();
- logs.forEach(log -> {
- createdLogs.add(save(log));
- });
+ logs.forEach(log ->
+ createdLogs.add(save(log))
+ );
return createdLogs;
}
@@ -139,8 +140,9 @@ public Log update(Log log) {
return resp.source();
}
} catch (Exception e) {
- logger.log(Level.SEVERE, "Failed to save log entry: " + log, e);
- throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, "Failed to update log entry: " + log);
+ String message = MessageFormat.format(TextUtil.LOG_NOT_UPDATED, log);
+ logger.log(Level.SEVERE, message, e);
+ throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, message);
}
return null;
}
@@ -151,7 +153,7 @@ public Log archive(Log log) {
GetResponse resp = client.get(GetRequest.of(g ->
g.index(ES_LOG_INDEX).id(String.valueOf(log.getId()))), Log.class);
if(!resp.found()) {
- logger.log(Level.SEVERE, "Failed to archive log with id: " + log.getId());
+ logger.log(Level.SEVERE, () -> MessageFormat.format(TextUtil.LOG_NOT_ARCHIVED, log.getId()));
} else {
Log originalDocument = resp.source();
String updatedVersion = originalDocument.getId() + "_v" + resp.version();
@@ -168,11 +170,11 @@ public Log archive(Log log) {
g.index(ES_LOG_ARCHIVE_INDEX).id(response.id()));
return client.get(getRequest, Log.class).source();
} else {
- logger.log(Level.SEVERE, "Failed to archiver log with id: " + updatedVersion);
+ logger.log(Level.SEVERE, () -> MessageFormat.format(TextUtil.LOG_NOT_ARCHIVED, updatedVersion));
}
}
} catch (IOException e) {
- logger.log(Level.SEVERE, "Failed to archiver log with id: " + log.getId(), e);
+ logger.log(Level.SEVERE, MessageFormat.format(TextUtil.LOG_NOT_ARCHIVED, log.getId()), e);
}
return null;
}
@@ -194,8 +196,8 @@ public SearchResult findArchivedById(String id) {
searchResult.setLogs(result);
return searchResult;
} catch (IOException | IllegalArgumentException e) {
- logger.log(Level.SEVERE, "Failed to complete search for archived logs", e);
- throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, "Failed to complete search archived logs");
+ logger.log(Level.SEVERE, TextUtil.LOGS_SEARCH_NOT_COMPLETED, e);
+ throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, TextUtil.LOGS_SEARCH_NOT_COMPLETED);
}
}
@@ -209,13 +211,14 @@ public Optional findById(String id) {
client.get(getRequest, Log.class);
if (!resp.found()) {
- throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Log with id " + id + " not found.");
+ throw new ResponseStatusException(HttpStatus.NOT_FOUND, MessageFormat.format(TextUtil.LOG_NOT_FOUND, id));
}
return Optional.of(resp.source());
} catch (Exception e) {
// https://www.baeldung.com/exception-handling-for-rest-with-spring#controlleradvice
- logger.log(Level.SEVERE, "Failed to retrieve log with id: " + id, e);
- throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Failed to retrieve log with id: " + id);
+ String message = MessageFormat.format(TextUtil.LOG_NOT_RETRIEVED, id);
+ logger.log(Level.SEVERE, message, e);
+ throw new ResponseStatusException(HttpStatus.NOT_FOUND, message);
}
}
@@ -225,14 +228,15 @@ public boolean existsById(String logId) {
ExistsRequest existsRequest = ExistsRequest.of(e -> e.index(ES_LOG_INDEX).id(logId));
return client.exists(existsRequest).value();
} catch (IOException e) {
- logger.log(Level.SEVERE, "Failed to check existence of log with id: " + logId, e);
- throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Failed to check existence of log with id: " + logId);
+ String message = MessageFormat.format(TextUtil.LOG_EXISTS_FAILED, logId);
+ logger.log(Level.SEVERE, message, e);
+ throw new ResponseStatusException(HttpStatus.NOT_FOUND, message);
}
}
@Override
public Iterable findAll() {
- throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Retrieving all log entries is not supported. Use Search with scroll.");
+ throw new ResponseStatusException(HttpStatus.NOT_FOUND, TextUtil.LOGS_RETRIEVE_ALL_NOT_SUPPORTED);
}
@Override
@@ -251,8 +255,9 @@ public Iterable findAllById(Iterable logIds) {
}
return foundLogs;
} catch (Exception e) {
- logger.log(Level.SEVERE, "Failed to find logs: " + logIds, e);
- throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Failed to find logs: " + logIds);
+ String message = MessageFormat.format(TextUtil.LOGS_NOT_FOUND, logIds);
+ logger.log(Level.SEVERE, message, e);
+ throw new ResponseStatusException(HttpStatus.NOT_FOUND, message);
}
}
@@ -263,22 +268,22 @@ public long count() {
@Override
public void deleteById(String id) {
- throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Deleting log entries is not supported");
+ throw new ResponseStatusException(HttpStatus.NOT_FOUND, TextUtil.LOGS_DELETE_NOT_SUPPORTED);
}
@Override
public void delete(Log entity) {
- throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Deleting log entries is not supported");
+ throw new ResponseStatusException(HttpStatus.NOT_FOUND, TextUtil.LOGS_DELETE_NOT_SUPPORTED);
}
@Override
public void deleteAll(Iterable extends Log> entities) {
- throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Deleting log entries is not supported");
+ throw new ResponseStatusException(HttpStatus.NOT_FOUND, TextUtil.LOGS_DELETE_NOT_SUPPORTED);
}
@Override
public void deleteAll() {
- throw new ResponseStatusException(HttpStatus.FORBIDDEN, "Deleting log entries is not supported");
+ throw new ResponseStatusException(HttpStatus.FORBIDDEN, TextUtil.LOGS_DELETE_NOT_SUPPORTED);
}
@Autowired
@@ -295,8 +300,8 @@ public SearchResult search(MultiValueMap searchParameters) {
searchResult.setLogs(result);
return searchResult;
} catch (IOException | IllegalArgumentException e) {
- logger.log(Level.SEVERE, "Failed to complete search", e);
- throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, "Failed to complete search");
+ logger.log(Level.SEVERE, TextUtil.SEARCH_NOT_COMPLETED, e);
+ throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, TextUtil.SEARCH_NOT_COMPLETED);
}
}
diff --git a/src/main/java/org/phoebus/olog/LogResource.java b/src/main/java/org/phoebus/olog/LogResource.java
index 08404e9..e92b95d 100644
--- a/src/main/java/org/phoebus/olog/LogResource.java
+++ b/src/main/java/org/phoebus/olog/LogResource.java
@@ -12,7 +12,6 @@
import org.phoebus.olog.notification.LogEntryNotifier;
import org.phoebus.util.time.TimeParser;
import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.InputStreamResource;
import org.springframework.core.io.Resource;
import org.springframework.core.task.TaskExecutor;
@@ -25,6 +24,7 @@
import java.io.IOException;
import java.security.Principal;
+import java.text.MessageFormat;
import java.time.Instant;
import java.time.temporal.TemporalAmount;
import java.time.temporal.UnsupportedTemporalTypeException;
@@ -96,8 +96,9 @@ public Log getLog(@PathVariable String logId) {
if (foundLog.isPresent()) {
return foundLog.get();
} else {
- logger.log(Level.SEVERE, "Failed to find log: " + logId, new ResponseStatusException(HttpStatus.NOT_FOUND));
- throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Failed to find log: " + logId);
+ String message = MessageFormat.format(TextUtil.LOG_NOT_FOUND, logId);
+ logger.log(Level.SEVERE, message, new ResponseStatusException(HttpStatus.NOT_FOUND));
+ throw new ResponseStatusException(HttpStatus.NOT_FOUND, message);
}
}
@@ -115,7 +116,7 @@ public ResponseEntity findResources(@PathVariable String logId, @PathV
Set attachments = log.get().getAttachments().stream().filter(attachment -> attachment.getFilename().equals(attachmentName)).collect(Collectors.toSet());
if (attachments.size() == 1) {
Attachment attachment = attachments.iterator().next();
- this.logger.log(Level.INFO, "Requesting attachment " + attachment.getId() + ": " + attachment.getFilename());
+ this.logger.log(Level.INFO, () -> MessageFormat.format(TextUtil.ATTACHMENT_REQUEST_DETAILS, attachment.getId(), attachment.getFilename()));
Attachment foundAttachment = attachmentRepository.findById(attachment.getId()).get();
InputStreamResource resource;
try {
@@ -132,11 +133,11 @@ public ResponseEntity findResources(@PathVariable String logId, @PathV
return new ResponseEntity<>(resource, httpHeaders, HttpStatus.OK);
} catch (IOException e) {
Logger.getLogger(LogResource.class.getName())
- .log(Level.WARNING, String.format("Unable to retrieve attachment %s for log id %s", attachmentName, logId), e);
+ .log(Level.WARNING, MessageFormat.format(TextUtil.ATTACHMENT_UNABLE_TO_RETRIEVE_FOR_ID, attachmentName, logId), e);
}
} else {
Logger.getLogger(LogResource.class.getName())
- .log(Level.WARNING, String.format("Found %d attachments named %s for log id %s", attachments.size(), attachmentName, logId));
+ .log(Level.WARNING, () -> MessageFormat.format(TextUtil.ATTACHMENTS_NAMED_FOUND_FOR_ID, attachments.size(), attachmentName, logId));
}
}
return null;
@@ -186,7 +187,7 @@ public SearchResult search(@RequestHeader(value = OLOG_CLIENT_INFO_HEADER, requi
try {
allRequestParams.get(key).add(MILLI_FORMAT.format(Instant.now().minus((TemporalAmount) time)));
} catch (UnsupportedTemporalTypeException e) { // E.g. if client sends "months" or "years"
- throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "Unsupported date/time specified: " + value);
+ throw new ResponseStatusException(HttpStatus.BAD_REQUEST, MessageFormat.format(TextUtil.UNSUPPORTED_DATE_TIME, value));
}
}
}
@@ -217,10 +218,10 @@ public Log createLog(@RequestHeader(value = OLOG_CLIENT_INFO_HEADER, required =
@RequestBody Log log,
@AuthenticationPrincipal Principal principal) {
if (log.getLogbooks().isEmpty()) {
- throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "A log entry must specify at least one logbook");
+ throw new ResponseStatusException(HttpStatus.BAD_REQUEST, TextUtil.LOG_MUST_HAVE_LOGBOOK);
}
if (log.getTitle().isEmpty()) {
- throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "A log entry must specify a title");
+ throw new ResponseStatusException(HttpStatus.BAD_REQUEST, TextUtil.LOG_MUST_HAVE_TITLE);
}
if (!inReplyTo.equals("-1")) {
handleReply(inReplyTo, log);
@@ -230,7 +231,7 @@ public Log createLog(@RequestHeader(value = OLOG_CLIENT_INFO_HEADER, required =
Set persistedLogbookNames = new HashSet<>();
logbookRepository.findAll().forEach(l -> persistedLogbookNames.add(l.getName()));
if (!CollectionUtils.containsAll(persistedLogbookNames, logbookNames)) {
- throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "One or more invalid logbook name(s)");
+ throw new ResponseStatusException(HttpStatus.BAD_REQUEST, TextUtil.LOG_INVALID_LOGBOOKS);
}
Set tags = log.getTags();
if (tags != null && !tags.isEmpty()) {
@@ -238,7 +239,7 @@ public Log createLog(@RequestHeader(value = OLOG_CLIENT_INFO_HEADER, required =
Set persistedTags = new HashSet<>();
tagRepository.findAll().forEach(t -> persistedTags.add(t.getName()));
if (!CollectionUtils.containsAll(persistedTags, tagNames)) {
- throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "One or more invalid tag name(s)");
+ throw new ResponseStatusException(HttpStatus.BAD_REQUEST, TextUtil.LOG_INVALID_TAGS);
}
}
log = cleanMarkup(markup, log);
@@ -246,7 +247,7 @@ public Log createLog(@RequestHeader(value = OLOG_CLIENT_INFO_HEADER, required =
Log newLogEntry = logRepository.save(log);
sendToNotifiers(newLogEntry);
- logger.log(Level.INFO, "Entry id " + newLogEntry.getId() + " created from " + clientInfo);
+ logger.log(Level.INFO, () -> "Entry id " + newLogEntry.getId() + " created from " + clientInfo);
return newLogEntry;
}
@@ -278,7 +279,7 @@ public Log createLog(@RequestHeader(value = OLOG_CLIENT_INFO_HEADER, required =
@AuthenticationPrincipal Principal principal) {
if (files != null && logEntry.getAttachments() != null && files.length != logEntry.getAttachments().size()) {
- throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "Attachment data invalid: file count does not match attachment count");
+ throw new ResponseStatusException(HttpStatus.BAD_REQUEST, TextUtil.ATTACHMENT_DATA_INVALID);
}
Log newLogEntry = createLog(clientInfo, markup, inReplyTo, logEntry, principal);
@@ -290,7 +291,7 @@ public Log createLog(@RequestHeader(value = OLOG_CLIENT_INFO_HEADER, required =
logEntry.getAttachments().stream()
.filter(a -> a.getFilename() != null && a.getFilename().equals(originalFileName)).findFirst();
if (attachment.isEmpty()) { // Should not happen if client behaves correctly
- logger.log(Level.WARNING, "File " + originalFileName + " not matched with attachment meta-data");
+ logger.log(Level.WARNING, () -> MessageFormat.format(TextUtil.ATTACHMENT_FILE_NOT_MATCHED_META_DATA, originalFileName));
continue;
}
uploadAttachment(Long.toString(newLogEntry.getId()),
@@ -301,7 +302,7 @@ public Log createLog(@RequestHeader(value = OLOG_CLIENT_INFO_HEADER, required =
}
}
- logger.log(Level.INFO, "Entry id " + newLogEntry.getId() + " created from " + clientInfo);
+ logger.log(Level.INFO, () -> MessageFormat.format(TextUtil.LOG_ENTRY_ID_CREATED_FROM, newLogEntry.getId(), clientInfo));
return newLogEntry;
}
@@ -338,7 +339,7 @@ public Log uploadAttachment(@PathVariable String logId,
log.setAttachments(existingAttachments);
return logRepository.update(log);
} else {
- throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Failed to retrieve log with id: " + logId);
+ throw new ResponseStatusException(HttpStatus.NOT_FOUND, MessageFormat.format(TextUtil.LOG_NOT_RETRIEVED, logId));
}
}
@@ -368,7 +369,7 @@ public Log updateLog(@PathVariable String logId,
// In case a client sends a log record where the id does not match the path variable, return HTTP 400 (bad request)
if (!logId.equals(Long.toString(log.getId()))) {
- throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "Log entry id does not match path variable");
+ throw new ResponseStatusException(HttpStatus.BAD_REQUEST, TextUtil.LOG_ENTRY_NOT_MATCH_PATH);
}
Optional foundLog = logRepository.findById(logId);
@@ -389,14 +390,14 @@ public Log updateLog(@PathVariable String logId,
return logRepository.update(persistedLog);
} else {
- throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Failed to retrieve log with id: " + logId);
+ throw new ResponseStatusException(HttpStatus.NOT_FOUND, MessageFormat.format(TextUtil.LOG_NOT_RETRIEVED, logId));
}
}
@SuppressWarnings("unused")
@PostMapping(value = "/group")
public void groupLogEntries(@RequestBody List logEntryIds) {
- logger.log(Level.INFO, "Grouping log entries: " + logEntryIds.stream().map(id -> Long.toString(id)).collect(Collectors.joining(",")));
+ logger.log(Level.INFO, () -> "Grouping log entries: " + logEntryIds.stream().map(id -> Long.toString(id)).collect(Collectors.joining(",")));
Property existingLogEntryGroupProperty = null;
List logs = new ArrayList<>();
// Check prerequisites: if two (or more) log entries are already contained in a group, they must all be contained in
@@ -407,13 +408,13 @@ public void groupLogEntries(@RequestBody List logEntryIds) {
try {
log = logRepository.findById(Long.toString(id));
} catch (ResponseStatusException exception) {
- throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "Log id " + id + " not found");
+ throw new ResponseStatusException(HttpStatus.BAD_REQUEST, MessageFormat.format(TextUtil.LOG_ID_NOT_FOUND, id));
}
Property logEntryGroupProperty = LogEntryGroupHelper.getLogEntryGroupProperty(log.get());
if (logEntryGroupProperty != null && existingLogEntryGroupProperty != null &&
!logEntryGroupProperty.getAttribute(LogEntryGroupHelper.ATTRIBUTE_ID).equals(existingLogEntryGroupProperty.getAttribute(LogEntryGroupHelper.ATTRIBUTE_ID))) {
- logger.log(Level.INFO, "Grouping not allowed due to conflicting log entry groups.");
- throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "Cannot group: at least two entries already contained in different groups");
+ logger.log(Level.INFO, TextUtil.GROUPING_NOT_ALLOWED);
+ throw new ResponseStatusException(HttpStatus.BAD_REQUEST, TextUtil.GROUPING_ENTRIES_IN_DIFFERENT_GROUPS);
}
if (logEntryGroupProperty != null) {
existingLogEntryGroupProperty = logEntryGroupProperty;
@@ -456,7 +457,7 @@ private void sendToNotifiers(Log log) {
n.notify(log);
} catch (Exception e) {
Logger.getLogger(LogResource.class.getName())
- .log(Level.WARNING, "LogEntryNotifier " + n.getClass().getName() + " throws exception", e);
+ .log(Level.WARNING, MessageFormat.format(TextUtil.LOG_ENTRY_NOTIFIER, n.getClass().getName()), e);
}
}));
}
@@ -493,7 +494,7 @@ public Log uploadMultipleAttachments(@PathVariable String logId,
}
return logRepository.findById(logId).get();
} else {
- throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Failed to retrieve log with id: " + logId);
+ throw new ResponseStatusException(HttpStatus.NOT_FOUND, MessageFormat.format(TextUtil.LOG_NOT_RETRIEVED, logId));
}
}
@@ -518,7 +519,7 @@ private void addPropertiesFromProviders(Log log) {
allFutures.get(propertyProvidersTimeout, TimeUnit.MILLISECONDS);
} catch (Exception e) {
Logger.getLogger(LogResource.class.getName())
- .log(Level.SEVERE, "A property provider failed to return in time or threw exception", e);
+ .log(Level.SEVERE, TextUtil.PROPERTY_PROVIDER_FAILED_TO_RETURN, e);
}
List providedProperties =
completableFutures.stream()
@@ -544,7 +545,7 @@ private void logSearchRequest(String clientInfo, MultiValueMap a
String toLog = allSearchParameters.entrySet().stream()
.map((e) -> e.getKey().trim() + "=" + e.getValue().stream().collect(Collectors.joining(",")))
.collect(Collectors.joining("&"));
- logger.log(Level.INFO, "Query " + toLog + " from client " + clientInfo);
+ logger.log(Level.INFO, () -> MessageFormat.format(TextUtil.QUERY_FROM_CLIENT, toLog, clientInfo));
}
/**
@@ -574,7 +575,7 @@ private void handleReply(String originalLogEntryId, Log log) {
}
} catch (ResponseStatusException exception) {
// Log entry not found, return HTTP 400
- throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "Cannot reply to log entry " + originalLogEntryId + " as it does not exist");
+ throw new ResponseStatusException(HttpStatus.BAD_REQUEST, MessageFormat.format(TextUtil.LOG_ENTRY_CANNOT_REPLY_NOT_EXISTS, originalLogEntryId));
}
}
}
diff --git a/src/main/java/org/phoebus/olog/LogSearchUtil.java b/src/main/java/org/phoebus/olog/LogSearchUtil.java
index ad3bd3d..a7964db 100644
--- a/src/main/java/org/phoebus/olog/LogSearchUtil.java
+++ b/src/main/java/org/phoebus/olog/LogSearchUtil.java
@@ -21,6 +21,7 @@
import org.springframework.util.MultiValueMap;
import org.springframework.web.server.ResponseStatusException;
+import java.text.MessageFormat;
import java.time.Instant;
import java.time.ZoneId;
import java.time.ZonedDateTime;
@@ -45,8 +46,8 @@
@Service
public class LogSearchUtil {
- final private static String MILLI_PATTERN = "yyyy-MM-dd HH:mm:ss.SSS";
- final public static DateTimeFormatter MILLI_FORMAT = DateTimeFormatter.ofPattern(MILLI_PATTERN).withZone(ZoneId.systemDefault());
+ private static final String MILLI_PATTERN = "yyyy-MM-dd HH:mm:ss.SSS";
+ public static final DateTimeFormatter MILLI_FORMAT = DateTimeFormatter.ofPattern(MILLI_PATTERN).withZone(ZoneId.systemDefault());
@SuppressWarnings("unused")
@Value("${elasticsearch.log.index:olog_logs}")
@@ -234,7 +235,7 @@ public SearchRequest buildSearchRequest(MultiValueMap searchPara
try {
searchResultSize = Integer.valueOf(maxSize.get());
} catch (NumberFormatException e) {
- LOGGER.log(Level.WARNING, "Cannot parse size value\"" + maxSize.get() + "\" as number");
+ LOGGER.log(Level.WARNING, () -> MessageFormat.format(TextUtil.SEARCH_CANNOT_PARSE_SIZE_VALUE, maxSize.get()));
}
}
break;
@@ -244,7 +245,7 @@ public SearchRequest buildSearchRequest(MultiValueMap searchPara
try {
from = Integer.valueOf(maxFrom.get());
} catch (NumberFormatException e) {
- LOGGER.log(Level.WARNING, "Cannot parse from value\"" + maxFrom.get() + "\" as number");
+ LOGGER.log(Level.WARNING, () -> MessageFormat.format(TextUtil.SEARCH_CANNOT_PARSE_FROM_VALUE, maxFrom.get()));
}
}
break;
@@ -315,48 +316,48 @@ public SearchRequest buildSearchRequest(MultiValueMap searchPara
}
} else {
throw new ResponseStatusException(HttpStatus.BAD_REQUEST,
- "Failed to parse search parameters: " + searchParameters + ", CAUSE: Invalid start and end times");
+ MessageFormat.format(TextUtil.SEARCH_FAILED_PARSE_PARAMETERS_INVALID_START_END, searchParameters));
}
}
// Add the description query. Multiple search terms will be AND:ed.
if (!searchTerms.isEmpty()) {
if (fuzzySearch) {
- searchTerms.stream().forEach(searchTerm -> {
- boolQueryBuilder.must(FuzzyQuery.of(f -> f.field("description").value(searchTerm))._toQuery());
- });
+ searchTerms.stream().forEach(searchTerm ->
+ boolQueryBuilder.must(FuzzyQuery.of(f -> f.field("description").value(searchTerm))._toQuery())
+ );
} else {
- searchTerms.stream().forEach(searchTerm -> {
- boolQueryBuilder.must(WildcardQuery.of(w -> w.field("description").value(searchTerm))._toQuery());
- });
+ searchTerms.stream().forEach(searchTerm ->
+ boolQueryBuilder.must(WildcardQuery.of(w -> w.field("description").value(searchTerm))._toQuery())
+ );
}
}
// Add phrase queries for description key. Multiple search terms will be AND:ed.
if (!descriptionPhraseSearchTerms.isEmpty()) {
- descriptionPhraseSearchTerms.stream().forEach(phraseSearchTerm -> {
- boolQueryBuilder.must(MatchPhraseQuery.of(m -> m.field("description").query(phraseSearchTerm))._toQuery());
- });
+ descriptionPhraseSearchTerms.stream().forEach(phraseSearchTerm ->
+ boolQueryBuilder.must(MatchPhraseQuery.of(m -> m.field("description").query(phraseSearchTerm))._toQuery())
+ );
}
// Add the title query. Multiple search terms will be AND:ed.
if (!titleSearchTerms.isEmpty()) {
if (fuzzySearch) {
- titleSearchTerms.stream().forEach(searchTerm -> {
- boolQueryBuilder.must(FuzzyQuery.of(f -> f.field("title").value(searchTerm))._toQuery());
- });
+ titleSearchTerms.stream().forEach(searchTerm ->
+ boolQueryBuilder.must(FuzzyQuery.of(f -> f.field("title").value(searchTerm))._toQuery())
+ );
} else {
- titleSearchTerms.stream().forEach(searchTerm -> {
- boolQueryBuilder.must(WildcardQuery.of(w -> w.field("title").value(searchTerm))._toQuery());
- });
+ titleSearchTerms.stream().forEach(searchTerm ->
+ boolQueryBuilder.must(WildcardQuery.of(w -> w.field("title").value(searchTerm))._toQuery())
+ );
}
}
// Add phrase queries for title key. Multiple search terms will be AND:ed.
if (!titlePhraseSearchTerms.isEmpty()) {
- titlePhraseSearchTerms.stream().forEach(phraseSearchTerm -> {
- boolQueryBuilder.must(MatchPhraseQuery.of(m -> m.field("title").query(phraseSearchTerm))._toQuery());
- });
+ titlePhraseSearchTerms.stream().forEach(phraseSearchTerm ->
+ boolQueryBuilder.must(MatchPhraseQuery.of(m -> m.field("title").query(phraseSearchTerm))._toQuery())
+ );
}
// Add the level query
@@ -364,13 +365,13 @@ public SearchRequest buildSearchRequest(MultiValueMap searchPara
DisMaxQuery.Builder levelQuery = new DisMaxQuery.Builder();
List levelQueries = new ArrayList<>();
if (fuzzySearch) {
- levelSearchTerms.stream().forEach(searchTerm -> {
- levelQueries.add(FuzzyQuery.of(f -> f.field("level").value(searchTerm))._toQuery());
- });
+ levelSearchTerms.stream().forEach(searchTerm ->
+ levelQueries.add(FuzzyQuery.of(f -> f.field("level").value(searchTerm))._toQuery())
+ );
} else {
- levelSearchTerms.stream().forEach(searchTerm -> {
- levelQueries.add(WildcardQuery.of(w -> w.field("level").value(searchTerm))._toQuery());
- });
+ levelSearchTerms.stream().forEach(searchTerm ->
+ levelQueries.add(WildcardQuery.of(w -> w.field("level").value(searchTerm))._toQuery())
+ );
}
levelQuery.queries(levelQueries);
boolQueryBuilder.must(levelQuery.build()._toQuery());
@@ -407,7 +408,7 @@ public List getSearchTerms(String searchQueryTerms) {
return Arrays.stream(searchQueryTerms.split("[\\|,;\\s+]")).filter(t -> t.length() > 0).collect(Collectors.toList());
}
if (quoteCount % 2 == 1) {
- throw new IllegalArgumentException("Unbalanced quotes in search query");
+ throw new IllegalArgumentException(TextUtil.SEARCH_UNBALANCED_QUOTES);
}
// If we come this far then at least one quoted term is
// contained in user input
diff --git a/src/main/java/org/phoebus/olog/LogbookRepository.java b/src/main/java/org/phoebus/olog/LogbookRepository.java
index b8faa18..62ca5a0 100644
--- a/src/main/java/org/phoebus/olog/LogbookRepository.java
+++ b/src/main/java/org/phoebus/olog/LogbookRepository.java
@@ -39,13 +39,13 @@
import org.springframework.web.server.ResponseStatusException;
import java.io.IOException;
+import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.stream.Collectors;
-import java.util.stream.StreamSupport;
@Repository
public class LogbookRepository implements CrudRepository {
@@ -87,8 +87,9 @@ public S save(S logbook) {
}
return null;
} catch (Exception e) {
- logger.log(Level.SEVERE, "Failed to create logbook: " + logbook, e);
- throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, "Failed to create logbook: " + logbook);
+ String message = MessageFormat.format(TextUtil.LOGBOOK_NOT_CREATED, logbook);
+ logger.log(Level.SEVERE, message, e);
+ throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, message);
}
}
@@ -110,14 +111,15 @@ public Iterable saveAll(Iterable logbooks) {
logger.log(Level.SEVERE, responseItem.error().reason());
}
});
- throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR,
- "Failed to create logbooks: " + logbooks);
+ String message = MessageFormat.format(TextUtil.LOGBOOKS_NOT_CREATED, logbooks);
+ throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, message);
} else {
return logbooks;
}
} catch (IOException e) {
- logger.log(Level.SEVERE, "Failed to create logbooks: " + logbooks, e);
- throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, "Failed to create logbooks: " + logbooks);
+ String message = MessageFormat.format(TextUtil.LOGBOOKS_NOT_CREATED, logbooks);
+ logger.log(Level.SEVERE, message, e);
+ throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, message);
}
}
@@ -135,8 +137,9 @@ public Optional findById(String logbookName) {
return Optional.empty();
}
} catch (Exception e) {
- logger.log(Level.SEVERE, "Failed to find logbook: " + logbookName, e);
- throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Failed to find logbook: " + logbookName);
+ String message = MessageFormat.format(TextUtil.LOGBOOK_NOT_FOUND, logbookName);
+ logger.log(Level.SEVERE, message, e);
+ throw new ResponseStatusException(HttpStatus.NOT_FOUND, message);
}
}
@@ -147,9 +150,9 @@ public boolean existsById(String logbookName) {
builder.index(ES_LOGBOOK_INDEX).id(logbookName);
return client.exists(builder.build()).value();
} catch (ElasticsearchException | IOException e) {
- logger.log(Level.SEVERE, "Failed to check if logbook " + logbookName + " exists", e);
- throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR,
- "Failed to check if logbook exists by id: " + logbookName, null);
+ String message = MessageFormat.format(TextUtil.LOGBOOK_EXISTS_FAILED, logbookName);
+ logger.log(Level.SEVERE, message, e);
+ throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, message, null);
}
}
@@ -158,8 +161,9 @@ public boolean existsByIds(List logbookNames) {
boolean b = logbookNames.stream().allMatch(id -> existsById(id));
return b;
} catch (Exception e) {
- logger.log(Level.SEVERE, "Failed to find logbooks: " + logbookNames, e);
- throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Failed to find logbooks: " + logbookNames);
+ String message = MessageFormat.format(TextUtil.LOGBOOKS_NOT_FOUND_1, logbookNames);
+ logger.log(Level.SEVERE, message, e);
+ throw new ResponseStatusException(HttpStatus.NOT_FOUND, message);
}
}
@@ -178,8 +182,8 @@ public Iterable findAll() {
client.search(searchRequest, Logbook.class);
return response.hits().hits().stream().map(Hit::source).collect(Collectors.toList());
} catch (Exception e) {
- logger.log(Level.SEVERE, "Failed to find logbooks", e);
- throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, "Failed to find logbooks");
+ logger.log(Level.SEVERE, TextUtil.LOGBOOKS_NOT_FOUND, e);
+ throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, TextUtil.LOGBOOKS_NOT_FOUND);
}
}
@@ -198,14 +202,15 @@ public Iterable findAllById(Iterable logbookNames) {
}
return foundLogbooks;
} catch (Exception e) {
- logger.log(Level.SEVERE, "Failed to find logbooks: " + logbookNames, e);
- throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Failed to find logbooks: " + logbookNames);
+ String message = MessageFormat.format(TextUtil.LOGBOOKS_NOT_FOUND_1, logbookNames);
+ logger.log(Level.SEVERE, message, e);
+ throw new ResponseStatusException(HttpStatus.NOT_FOUND, message);
}
}
@Override
public long count() {
- throw new ResponseStatusException(HttpStatus.FORBIDDEN, "Count is not implemented");
+ throw new ResponseStatusException(HttpStatus.FORBIDDEN, TextUtil.COUNT_NOT_IMPLEMENTED);
}
@Override
@@ -226,12 +231,14 @@ public void deleteById(String logbookName) {
UpdateResponse updateResponse =
client.update(updateRequest, Logbook.class);
if (updateResponse.result().equals(co.elastic.clients.elasticsearch._types.Result.Updated)) {
- logger.log(Level.INFO, "Deleted logbook " + logbookName);
+ String message = MessageFormat.format(TextUtil.LOGBOOK_DELETE, logbookName);
+ logger.log(Level.INFO, () -> message);
}
}
} catch (Exception e) {
- logger.log(Level.SEVERE, "Failed to delete logbook: " + logbookName, e);
- throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, "Failed to delete logbook: " + logbookName);
+ String message = MessageFormat.format(TextUtil.LOGBOOK_NOT_DELETED, logbookName);
+ logger.log(Level.SEVERE, message, e);
+ throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, message);
}
}
@@ -247,7 +254,7 @@ public void deleteAll(Iterable extends Logbook> logbooks) {
@Override
public void deleteAll() {
- throw new ResponseStatusException(HttpStatus.FORBIDDEN, "Deleting all logbooks is not allowed");
+ throw new ResponseStatusException(HttpStatus.FORBIDDEN, TextUtil.LOGBOOKS_DELETE_ALL_NOT_ALLOWED);
}
@Override
diff --git a/src/main/java/org/phoebus/olog/LogbooksResource.java b/src/main/java/org/phoebus/olog/LogbooksResource.java
index 58ce10e..e7595e7 100644
--- a/src/main/java/org/phoebus/olog/LogbooksResource.java
+++ b/src/main/java/org/phoebus/olog/LogbooksResource.java
@@ -8,6 +8,7 @@
import static org.phoebus.olog.OlogResourceDescriptors.LOGBOOK_RESOURCE_URI;
import java.security.Principal;
+import java.text.MessageFormat;
import java.util.List;
import java.util.Optional;
import java.util.logging.Level;
@@ -56,8 +57,9 @@ public Logbook findByTitle(@PathVariable String logbookName) {
if (foundLogbook.isPresent()) {
return foundLogbook.get();
} else {
- log.log(Level.SEVERE, "Failed to find logbook: " + logbookName, new ResponseStatusException(HttpStatus.NOT_FOUND));
- throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Failed to find logbook: " + logbookName);
+ String message = MessageFormat.format(TextUtil.LOGBOOK_NOT_FOUND, logbookName);
+ log.log(Level.SEVERE, message, new ResponseStatusException(HttpStatus.NOT_FOUND));
+ throw new ResponseStatusException(HttpStatus.NOT_FOUND, message);
}
}
@@ -112,8 +114,9 @@ public void deleteLogbook (@PathVariable String logbookName) {
// delete existing logbook
logbookRepository.deleteById(logbookName);
} else {
- log.log(Level.SEVERE, "The logbook with the name " + logbookName + " does not exist", new ResponseStatusException(HttpStatus.NOT_FOUND));
- throw new ResponseStatusException(HttpStatus.NOT_FOUND, "The logbook with the name " + logbookName + " does not exist");
+ String message = MessageFormat.format(TextUtil.LOGBOOK_NOT_EXISTS, logbookName);
+ log.log(Level.SEVERE, message, new ResponseStatusException(HttpStatus.NOT_FOUND));
+ throw new ResponseStatusException(HttpStatus.NOT_FOUND, message);
}
}
@@ -147,9 +150,9 @@ public void validateLogbookRequest(Iterable logbooks) {
*/
public void validateLogbookRequest(Logbook logbook) {
if (logbook.getName() == null || logbook.getName().isEmpty()) {
- log.log(Level.SEVERE, "The logbook name cannot be null or empty " + logbook.toString(), new ResponseStatusException(HttpStatus.BAD_REQUEST));
- throw new ResponseStatusException(HttpStatus.BAD_REQUEST,
- "The logbook name cannot be null or empty " + logbook.toString(), null);
+ String message = MessageFormat.format(TextUtil.LOGBOOK_NAME_CANNOT_BE_NULL_OR_EMPTY, logbook.toString());
+ log.log(Level.SEVERE, message, new ResponseStatusException(HttpStatus.BAD_REQUEST));
+ throw new ResponseStatusException(HttpStatus.BAD_REQUEST, message, null);
}
}
diff --git a/src/main/java/org/phoebus/olog/PropertiesResource.java b/src/main/java/org/phoebus/olog/PropertiesResource.java
index 38a686d..b197645 100644
--- a/src/main/java/org/phoebus/olog/PropertiesResource.java
+++ b/src/main/java/org/phoebus/olog/PropertiesResource.java
@@ -7,8 +7,8 @@
import static org.phoebus.olog.OlogResourceDescriptors.PROPERTY_RESOURCE_URI;
-import java.io.IOException;
import java.security.Principal;
+import java.text.MessageFormat;
import java.util.List;
import java.util.Optional;
import java.util.logging.Level;
@@ -65,8 +65,9 @@ public Property findByTitle(@PathVariable String propertyName) {
if (foundProperty.isPresent()) {
return foundProperty.get();
} else {
- log.log(Level.SEVERE, "Failed to find property: " + propertyName, new ResponseStatusException(HttpStatus.NOT_FOUND));
- throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Failed to find property: " + propertyName);
+ String message = MessageFormat.format(TextUtil.PROPERTY_NOT_FOUND, propertyName);
+ log.log(Level.SEVERE, message, new ResponseStatusException(HttpStatus.NOT_FOUND));
+ throw new ResponseStatusException(HttpStatus.NOT_FOUND, message);
}
}
@@ -129,8 +130,9 @@ public void deleteProperty (@PathVariable String propertyName) {
// delete existing property
propertyRepository.deleteById(propertyName);
} else {
- log.log(Level.SEVERE, "The property with the name " + propertyName + " does not exist", new ResponseStatusException(HttpStatus.NOT_FOUND));
- throw new ResponseStatusException(HttpStatus.NOT_FOUND, "The property with the name " + propertyName + " does not exist");
+ String message = MessageFormat.format(TextUtil.PROPERTY_NOT_EXISTS, propertyName);
+ log.log(Level.SEVERE, message, new ResponseStatusException(HttpStatus.NOT_FOUND));
+ throw new ResponseStatusException(HttpStatus.NOT_FOUND, message);
}
}
@@ -164,9 +166,9 @@ public void validatePropertyRequest(Iterable properties) {
*/
public void validatePropertyRequest(Property property) {
if (property.getName() == null || property.getName().isEmpty()) {
- log.log(Level.SEVERE, "The property name cannot be null or empty " + property.toString(), new ResponseStatusException(HttpStatus.BAD_REQUEST));
- throw new ResponseStatusException(HttpStatus.BAD_REQUEST,
- "The property name cannot be null or empty " + property.toString(), null);
+ String message = MessageFormat.format(TextUtil.PROPERTY_NAME_CANNOT_BE_NULL_OR_EMPTY, property.toString());
+ log.log(Level.SEVERE, message, new ResponseStatusException(HttpStatus.BAD_REQUEST));
+ throw new ResponseStatusException(HttpStatus.BAD_REQUEST, message, null);
}
validateAttributeRequest(property.getAttributes());
@@ -202,9 +204,9 @@ public void validateAttributeRequest(Iterable attributes) {
*/
public void validateAttributeRequest(Attribute attribute) {
if (attribute.getName() == null || attribute.getName().isEmpty()) {
- log.log(Level.SEVERE, "The attribute name cannot be null or empty " + attribute.toString(), new ResponseStatusException(HttpStatus.BAD_REQUEST));
- throw new ResponseStatusException(HttpStatus.BAD_REQUEST,
- "The attribute name cannot be null or empty " + attribute.toString(), null);
+ String message = MessageFormat.format(TextUtil.ATTRIBUTE_NAME_CANNOT_BE_NULL_OR_EMPTY, attribute.toString());
+ log.log(Level.SEVERE, message, new ResponseStatusException(HttpStatus.BAD_REQUEST));
+ throw new ResponseStatusException(HttpStatus.BAD_REQUEST, message, null);
}
}
diff --git a/src/main/java/org/phoebus/olog/PropertyRepository.java b/src/main/java/org/phoebus/olog/PropertyRepository.java
index 0449524..9f92f8c 100644
--- a/src/main/java/org/phoebus/olog/PropertyRepository.java
+++ b/src/main/java/org/phoebus/olog/PropertyRepository.java
@@ -42,6 +42,7 @@
import org.springframework.web.server.ResponseStatusException;
import java.io.IOException;
+import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
@@ -88,8 +89,9 @@ public S save(S property) {
}
return null;
} catch (Exception e) {
- logger.log(Level.SEVERE, "Failed to create property: " + property, e);
- throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, "Failed to create property: " + property);
+ String message = MessageFormat.format(TextUtil.PROPERTY_NOT_CREATED, property);
+ logger.log(Level.SEVERE, message, e);
+ throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, message);
}
}
@@ -112,15 +114,16 @@ public Iterable saveAll(Iterable properties) {
logger.log(Level.SEVERE, responseItem.error().reason());
}
});
- throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR,
- "Failed to create properties: " + properties);
+ String message = MessageFormat.format(TextUtil.PROPERTIES_NOT_CREATED, properties);
+ throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, message);
} else {
return properties;
}
} catch (IOException e) {
- logger.log(Level.SEVERE, "Failed to create properties: " + properties, e);
- throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, "Failed to create properties: " + properties);
+ String message = MessageFormat.format(TextUtil.PROPERTIES_NOT_CREATED, properties);
+ logger.log(Level.SEVERE, message, e);
+ throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, message);
}
}
@@ -138,8 +141,9 @@ public Optional findById(String propertyName) {
return Optional.empty();
}
} catch (Exception e) {
- logger.log(Level.SEVERE, "Failed to find property: " + propertyName, e);
- throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Failed to find property: " + propertyName);
+ String message = MessageFormat.format(TextUtil.PROPERTY_NOT_FOUND, propertyName);
+ logger.log(Level.SEVERE, message, e);
+ throw new ResponseStatusException(HttpStatus.NOT_FOUND, message);
}
}
@@ -150,9 +154,9 @@ public boolean existsById(String propertyName) {
builder.index(ES_PROPERTY_INDEX).id(propertyName);
return client.exists(builder.build()).value();
} catch (ElasticsearchException | IOException e) {
- logger.log(Level.SEVERE, "Failed to check if property " + propertyName + " exists", e);
- throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR,
- "Failed to check if property exists by id: " + propertyName, null);
+ String message = MessageFormat.format(TextUtil.PROPERTY_EXISTS_FAILED, propertyName);
+ logger.log(Level.SEVERE, message, e);
+ throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, message, null);
}
}
@@ -182,8 +186,8 @@ public Iterable findAll(boolean includeInactive) {
return response.hits().hits().stream().map(Hit::source).collect(Collectors.toList());
} catch (Exception e) {
- logger.log(Level.SEVERE, "Failed to find properties", e);
- throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, "Failed to find properties");
+ logger.log(Level.SEVERE, TextUtil.PROPERTIES_NOT_FOUND, e);
+ throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, TextUtil.PROPERTIES_NOT_FOUND);
}
}
@@ -202,8 +206,9 @@ public Iterable findAllById(Iterable propertyNames) {
}
return foundProperties;
} catch (Exception e) {
- logger.log(Level.SEVERE, "Failed to find properties: " + propertyNames, e);
- throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Failed to find properties: " + propertyNames);
+ String message = MessageFormat.format(TextUtil.PROPERTIES_NOT_FOUND_1, propertyNames);
+ logger.log(Level.SEVERE, message, e);
+ throw new ResponseStatusException(HttpStatus.NOT_FOUND, message);
}
}
@@ -231,12 +236,14 @@ public void deleteById(String propertyName) {
UpdateResponse updateResponse =
client.update(updateRequest, Property.class);
if (updateResponse.result().equals(co.elastic.clients.elasticsearch._types.Result.Updated)) {
- logger.log(Level.INFO, "Deleted property " + propertyName);
+ String message = MessageFormat.format(TextUtil.PROPERTY_DELETE, propertyName);
+ logger.log(Level.INFO, () -> message);
}
}
} catch (Exception e) {
- logger.log(Level.SEVERE, "Failed to delete property: " + propertyName, e);
- throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, "Failed to delete property: " + propertyName);
+ String message = MessageFormat.format(TextUtil.PROPERTY_NOT_DELETED, propertyName);
+ logger.log(Level.SEVERE, message, e);
+ throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, message);
}
}
@@ -244,8 +251,7 @@ public void deleteAttribute(String propertyName, String attributeName) {
try {
Optional optional = findById(propertyName);
if (optional.isEmpty()) {
- logger.log(Level.SEVERE, "Cannot delete attribute " + attributeName +
- " from property " + propertyName + " as the property does not exist");
+ logger.log(Level.SEVERE, () -> MessageFormat.format(TextUtil.PROPERTY_ATTRIBUTE_CANNOT_DELETE, attributeName, propertyName));
return;
}
Property property = optional.get();
@@ -270,7 +276,7 @@ public void deleteAttribute(String propertyName, String attributeName) {
GetResponse resp =
client.get(getRequest, Property.class);
Property deletedProperty = resp.source();
- logger.log(Level.INFO, "Deleted property attribute" + deletedProperty.toLogger());
+ logger.log(Level.INFO, () -> MessageFormat.format(TextUtil.PROPERTY_ATTRIBUTE_DELETE, deletedProperty.toLogger()));
}
} catch (Exception e) {
logger.log(Level.SEVERE, e.getMessage(), e);
@@ -289,7 +295,7 @@ public void deleteAll(Iterable extends Property> properties) {
@Override
public void deleteAll() {
- throw new ResponseStatusException(HttpStatus.FORBIDDEN, "Deleting all properties is not allowed");
+ throw new ResponseStatusException(HttpStatus.FORBIDDEN, TextUtil.PROPERTIES_DELETE_ALL_NOT_ALLOWED);
}
@Override
diff --git a/src/main/java/org/phoebus/olog/SequenceGenerator.java b/src/main/java/org/phoebus/olog/SequenceGenerator.java
index da282f0..58748cf 100644
--- a/src/main/java/org/phoebus/olog/SequenceGenerator.java
+++ b/src/main/java/org/phoebus/olog/SequenceGenerator.java
@@ -1,34 +1,19 @@
/**
- *
+ *
*/
package org.phoebus.olog;
import java.io.IOException;
import java.time.Instant;
-import java.util.logging.Level;
-import java.util.logging.Logger;
import javax.annotation.PostConstruct;
import co.elastic.clients.elasticsearch.ElasticsearchClient;
-import co.elastic.clients.elasticsearch._types.ElasticsearchException;
-import co.elastic.clients.elasticsearch._types.FieldSort;
import co.elastic.clients.elasticsearch._types.Refresh;
-import co.elastic.clients.elasticsearch._types.SortOptions;
-import co.elastic.clients.elasticsearch._types.SortOrder;
-import co.elastic.clients.elasticsearch._types.query_dsl.BoolQuery;
-import co.elastic.clients.elasticsearch._types.query_dsl.BoolQuery.Builder;
-import co.elastic.clients.elasticsearch._types.query_dsl.MatchAllQuery;
-import co.elastic.clients.elasticsearch._types.query_dsl.RangeQuery;
-import co.elastic.clients.elasticsearch._types.query_dsl.TermQuery;
import co.elastic.clients.elasticsearch.core.IndexRequest;
-import co.elastic.clients.elasticsearch.core.IndexResponse;
-import co.elastic.clients.elasticsearch.core.SearchRequest;
-import co.elastic.clients.elasticsearch.core.SearchResponse;
import co.elastic.clients.json.JsonData;
import co.elastic.clients.json.jackson.JacksonJsonpMapper;
import com.fasterxml.jackson.databind.ObjectMapper;
-import org.phoebus.olog.entity.Log;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
@@ -69,7 +54,7 @@ public void init()
/**
* get a new unique id from the olog_sequnce index
- *
+ *
* @return a new unique id for a olog entry
* @throws IOException The Elasticsearch client may throw this
*/
diff --git a/src/main/java/org/phoebus/olog/TagRepository.java b/src/main/java/org/phoebus/olog/TagRepository.java
index 9ddd6af..bd9b821 100644
--- a/src/main/java/org/phoebus/olog/TagRepository.java
+++ b/src/main/java/org/phoebus/olog/TagRepository.java
@@ -39,6 +39,7 @@
import org.springframework.web.server.ResponseStatusException;
import java.io.IOException;
+import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
@@ -87,8 +88,9 @@ public S save(S tag) {
}
return null;
} catch (Exception e) {
- logger.log(Level.SEVERE, "Failed to create tag: " + tag, e);
- throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, "Failed to create tag: " + tag);
+ String message = MessageFormat.format(TextUtil.TAG_NOT_CREATED, tag);
+ logger.log(Level.SEVERE, message, e);
+ throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, message);
}
}
@@ -111,14 +113,15 @@ public Iterable saveAll(Iterable tags) {
logger.log(Level.SEVERE, responseItem.error().reason());
}
});
- throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR,
- "Failed to create logbooks: " + tags);
+ String message = MessageFormat.format(TextUtil.TAGS_NOT_CREATED, tags);
+ throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, message);
} else {
return tags;
}
} catch (IOException e) {
- logger.log(Level.SEVERE, "Failed to create tags: " + tags, e);
- throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, "Failed to create tags: " + tags);
+ String message = MessageFormat.format(TextUtil.TAGS_NOT_CREATED, tags);
+ logger.log(Level.SEVERE, message, e);
+ throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, message);
}
}
@@ -136,8 +139,9 @@ public Optional findById(String tagName) {
return Optional.empty();
}
} catch (Exception e) {
- logger.log(Level.SEVERE, "Failed to find tag: " + tagName, e);
- throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Failed to find tag: " + tagName);
+ String message = MessageFormat.format(TextUtil.TAG_NOT_FOUND, tagName);
+ logger.log(Level.SEVERE, message, e);
+ throw new ResponseStatusException(HttpStatus.NOT_FOUND, message);
}
}
@@ -148,9 +152,9 @@ public boolean existsById(String tagName) {
builder.index(ES_TAG_INDEX).id(tagName);
return client.exists(builder.build()).value();
} catch (ElasticsearchException | IOException e) {
- logger.log(Level.SEVERE, "Failed to check if tag " + tagName + " exists", e);
- throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR,
- "Failed to check if tag exists by id: " + tagName, null);
+ String message = MessageFormat.format(TextUtil.TAG_EXISTS_FAILED, tagName);
+ logger.log(Level.SEVERE, message, e);
+ throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, message, null);
}
}
@@ -170,8 +174,8 @@ public Iterable findAll() {
return response.hits().hits().stream().map(Hit::source).collect(Collectors.toList());
} catch (Exception e) {
- logger.log(Level.SEVERE, "Failed to find tags", e);
- throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Failed to find tags");
+ logger.log(Level.SEVERE, TextUtil.TAGS_NOT_FOUND, e);
+ throw new ResponseStatusException(HttpStatus.NOT_FOUND, TextUtil.TAGS_NOT_FOUND);
}
}
@@ -191,8 +195,9 @@ public Iterable findAllById(Iterable tagNames) {
}
return foundTags;
} catch (Exception e) {
- logger.log(Level.SEVERE, "Failed to find tags: " + tagNames, e);
- throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Failed to find tags: " + tagNames);
+ String message = MessageFormat.format(TextUtil.TAGS_NOT_FOUND_1, tagNames);
+ logger.log(Level.SEVERE, message, e);
+ throw new ResponseStatusException(HttpStatus.NOT_FOUND, message);
}
}
@@ -220,12 +225,14 @@ public void deleteById(String tagName) {
UpdateResponse updateResponse =
client.update(updateRequest, Tag.class);
if (updateResponse.result().equals(co.elastic.clients.elasticsearch._types.Result.Updated)) {
- logger.log(Level.INFO, "Deleted tag " + tagName);
+ String message = MessageFormat.format(TextUtil.TAG_DELETE, tagName);
+ logger.log(Level.INFO, () -> message);
}
}
} catch (Exception e) {
- logger.log(Level.SEVERE, "Failed to delete tag: " + tagName, e);
- throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, "Failed to delete tag: " + tagName);
+ String message = MessageFormat.format(TextUtil.TAG_NOT_DELETED, tagName);
+ logger.log(Level.SEVERE, message, e);
+ throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, message);
}
}
@@ -241,7 +248,7 @@ public void deleteAll(Iterable extends Tag> tags) {
@Override
public void deleteAll() {
- throw new ResponseStatusException(HttpStatus.FORBIDDEN, "Deleting all tags is not allowed");
+ throw new ResponseStatusException(HttpStatus.FORBIDDEN, TextUtil.TAGS_DELETE_ALL_NOT_ALLOWED);
}
@Override
diff --git a/src/main/java/org/phoebus/olog/TagsResource.java b/src/main/java/org/phoebus/olog/TagsResource.java
index f27e8a2..9690c6b 100644
--- a/src/main/java/org/phoebus/olog/TagsResource.java
+++ b/src/main/java/org/phoebus/olog/TagsResource.java
@@ -7,6 +7,7 @@
import static org.phoebus.olog.OlogResourceDescriptors.TAG_RESOURCE_URI;
+import java.text.MessageFormat;
import java.util.List;
import java.util.Optional;
import java.util.logging.Level;
@@ -39,8 +40,7 @@ public class TagsResource {
private TagRepository tagRepository;
/** Creates a new instance of TagsResource */
- public TagsResource()
- {
+ public TagsResource() {
}
/**
@@ -49,8 +49,7 @@ public TagsResource()
* @return list of tags
*/
@GetMapping
- public Iterable findAll()
- {
+ public Iterable findAll() {
return tagRepository.findAll();
}
@@ -61,14 +60,14 @@ public Iterable findAll()
* @return the matching tag, or null
*/
@GetMapping("/{tagName}")
- public Tag findByTitle(@PathVariable String tagName)
- {
+ public Tag findByTitle(@PathVariable String tagName) {
Optional foundTag = tagRepository.findById(tagName);
if (foundTag.isPresent()) {
return foundTag.get();
} else {
- log.log(Level.SEVERE, "Failed to find tag: " + tagName, new ResponseStatusException(HttpStatus.NOT_FOUND));
- throw new ResponseStatusException(HttpStatus.NOT_FOUND, "Failed to find tag: " + tagName);
+ String message = MessageFormat.format(TextUtil.TAG_NOT_FOUND, tagName);
+ log.log(Level.SEVERE, message, new ResponseStatusException(HttpStatus.NOT_FOUND));
+ throw new ResponseStatusException(HttpStatus.NOT_FOUND, message);
}
}
@@ -80,8 +79,7 @@ public Tag findByTitle(@PathVariable String tagName)
* @return the created tag
*/
@PutMapping("/{tagName}")
- public Tag createTag(@PathVariable String tagName, @RequestBody final Tag tag)
- {
+ public Tag createTag(@PathVariable String tagName, @RequestBody final Tag tag) {
// TODO Check permissions
// Validate
@@ -106,8 +104,7 @@ public Tag createTag(@PathVariable String tagName, @RequestBody final Tag tag)
* @return the list of tags created
*/
@PutMapping
- public Iterable updateTag(@RequestBody final List tags)
- {
+ public Iterable updateTag(@RequestBody final List tags) {
// TODO Check permissions
// Validate
@@ -127,8 +124,7 @@ public Iterable updateTag(@RequestBody final List tags)
}
@DeleteMapping("/{tagName}")
- public void deleteTag(@PathVariable String tagName)
- {
+ public void deleteTag(@PathVariable String tagName) {
// TODO Check permissions
// check if present
@@ -137,8 +133,9 @@ public void deleteTag(@PathVariable String tagName)
// delete existing tag
tagRepository.deleteById(tagName);
} else {
- log.log(Level.SEVERE, "The tag with the name " + tagName + " does not exist", new ResponseStatusException(HttpStatus.NOT_FOUND));
- throw new ResponseStatusException(HttpStatus.NOT_FOUND, "The tag with the name " + tagName + " does not exist");
+ String message = MessageFormat.format(TextUtil.TAG_NOT_EXISTS, tagName);
+ log.log(Level.SEVERE, message, new ResponseStatusException(HttpStatus.NOT_FOUND));
+ throw new ResponseStatusException(HttpStatus.NOT_FOUND, message);
}
}
@@ -170,9 +167,9 @@ public void validateTagRequest(Iterable tags) {
*/
public void validateTagRequest(Tag tag) {
if (tag.getName() == null || tag.getName().isEmpty()) {
- log.log(Level.SEVERE, "The tag name cannot be null or empty " + tag.toString(), new ResponseStatusException(HttpStatus.BAD_REQUEST));
- throw new ResponseStatusException(HttpStatus.BAD_REQUEST,
- "The tag name cannot be null or empty " + tag.toString(), null);
+ String message = MessageFormat.format(TextUtil.TAG_NAME_CANNOT_BE_NULL_OR_EMPTY, tag.toString());
+ log.log(Level.SEVERE, message, new ResponseStatusException(HttpStatus.BAD_REQUEST));
+ throw new ResponseStatusException(HttpStatus.BAD_REQUEST, message, null);
}
}
diff --git a/src/main/java/org/phoebus/olog/TextUtil.java b/src/main/java/org/phoebus/olog/TextUtil.java
new file mode 100644
index 0000000..00894ce
--- /dev/null
+++ b/src/main/java/org/phoebus/olog/TextUtil.java
@@ -0,0 +1,145 @@
+package org.phoebus.olog;
+
+/**
+ * Utility class to assist in handling of text.
+ *
+ * @author Lars Johansson
+ */
+public class TextUtil {
+
+ // common
+ // olog
+ // elastic
+ // attachment
+ // attribute
+ // logbook
+ // log
+ // property
+ // tag
+
+ // ----------------------------------------------------------------------------------------------------
+
+ public static final String COUNT_NOT_IMPLEMENTED = "Count is not implemented";
+ public static final String SEARCH_CANNOT_PARSE_FROM_VALUE = "Cannot parse from value {0} as number";
+ public static final String SEARCH_CANNOT_PARSE_SIZE_VALUE = "Cannot parse size value {0} as number";
+ public static final String SEARCH_FAILED_PARSE_PARAMETERS_INVALID_START_END = "Failed to parse search parameters: {0}, CAUSE: Invalid start and end times";
+ public static final String SEARCH_NOT_COMPLETED = "Failed to complete search";
+ public static final String SEARCH_UNBALANCED_QUOTES = "Unbalanced quotes in search query";
+
+ public static final String CONTENT_TYPE_NOT_DETERMINED = "Unable to determine content type from file name {0}";
+ public static final String GROUPING_NOT_ALLOWED = "Grouping not allowed due to conflicting log entry groups";
+ public static final String GROUPING_ENTRIES_IN_DIFFERENT_GROUPS = "Cannot group: at least two entries already contained in different groups";
+ public static final String HELP_REQUEST_WHAT_FOR_LANGUAGE = "Requesting {0} for language {1}";
+ public static final String HELP_UNABLE_READ_FOR_LANGUAGE_DEFAULT = "Unable to read {0} resource for language {1}, defaulting to 'en'";
+ public static final String HELP_UNABLE_FIND_RESOURCE = "Unable to read find resource {0}_en.html";
+ public static final String PROPERTY_PROVIDER_FAILED_TO_RETURN = "A property provider failed to return in time or threw exception";
+ public static final String QUERY_FROM_CLIENT = "Query {0} from client {1}";
+ public static final String UNSUPPORTED_DATE_TIME = "Unsupported date/time specified {0}";
+ public static final String USER_NOT_AUTHENTICATED_THROUGH_AUTHORIZATION_HEADER = "User {0} not authenticated through authorization header";
+
+ // ----------------------------------------------------------------------------------------------------
+
+ public static final String OLOG_STARTING = "Starting Olog Service";
+ public static final String OLOG_FAILED_CONFIGURE_TRUSTSTORE = "failed to configure olog truststore";
+ public static final String OLOG_FAILED_CREATE_SERVICE = "Failed to create Olog service info resource";
+
+ public static final String ELASTIC_CREATED_INDEX_ACKNOWLEDGED = "Created index {0} acknowledged {1}";
+ public static final String ELASTIC_FAILED_TO_CONNECT = "Failed to connect to elastic {0}";
+ public static final String ELASTIC_FAILED_TO_CREATE_INDEX = "Failed to create index {0}";
+ public static final String ELASTIC_FAILED_TO_INITIALIZE_LOGBOOK = "Failed to initialize logbook {0}";
+ public static final String ELASTIC_FAILED_TO_INITIALIZE_LOGBOOKS = "Failed to initialize logbooks";
+ public static final String ELASTIC_FAILED_TO_INITIALIZE_PROPERTY = "Failed to initialize property {0}";
+ public static final String ELASTIC_FAILED_TO_INITIALIZE_PROPERTIES = "Failed to initialize properties";
+ public static final String ELASTIC_FAILED_TO_INITIALIZE_TAG = "Failed to initialize tag {0}";
+ public static final String ELASTIC_FAILED_TO_INITIALIZE_TAGS = "Failed to initialize tags";
+
+ // ----------------------------------------------------------------------------------------------------
+
+ public static final String ATTACHMENT_DATA_INVALID = "Attachment data invalid: file count does not match attachment count";
+ public static final String ATTACHMENT_FILE_NOT_MATCHED_META_DATA = "File {0} not matched with attachment meta-data";
+ public static final String ATTACHMENT_NOT_FOUND = "Attachment with id {0} not found";
+ public static final String ATTACHMENT_NOT_PERSISTED = "Unable to persist attachment {0}";
+ public static final String ATTACHMENT_NOT_RETRIEVED = "Unable to retrieve attachment with id {0}";
+ public static final String ATTACHMENT_REQUEST = "Requesting attachment {0}";
+ public static final String ATTACHMENT_REQUEST_DETAILS = "Requesting attachment {0} : {1}";
+ public static final String ATTACHMENT_UNABLE_TO_RETRIEVE_FOR_ID = "Unable to retrieve attachment {0} for log id {1}";
+
+ public static final String ATTACHMENTS_NAMED_FOUND_FOR_ID = "Found {0} attachments named {1} for log id {2}";
+
+ public static final String ATTRIBUTE_NAME_CANNOT_BE_NULL_OR_EMPTY = "The attribute name cannot be null or empty {0}";
+
+ public static final String LOGBOOK_DELETE = "Deleted logbook {0}";
+ public static final String LOGBOOK_EXISTS_FAILED = "Failed to check if logbook {0} exists";
+ public static final String LOGBOOK_INVALID = "Logbook {0} is invalid";
+ public static final String LOGBOOK_NAME_CANNOT_BE_NULL_OR_EMPTY = "The logbook name cannot be null or empty {0}";
+ public static final String LOGBOOK_NOT_EXISTS = "The logbook {0} does not exist";
+ public static final String LOGBOOK_NOT_CREATED = "Failed to created logbook {0}";
+ public static final String LOGBOOK_NOT_DELETED = "Failed to delete logbook {0}";
+ public static final String LOGBOOK_NOT_FOUND = "Failed to find logbook {0}";
+
+ public static final String LOGBOOKS_DELETE_ALL_NOT_ALLOWED = "Deleting all logbooks is not allowed";
+ public static final String LOGBOOKS_NOT_CREATED = "Failed to created logbooks {0}";
+ public static final String LOGBOOKS_NOT_FOUND = "Failed to find logbooks";
+ public static final String LOGBOOKS_NOT_FOUND_1 = "Failed to find logbooks {0}";
+ public static final String LOGBOOKS_NOT_SPECIFIED = "No logbooks specified";
+
+ public static final String LOG_ENTRY_CANNOT_REPLY_NOT_EXISTS = "Cannot reply to log entry {0} as it does not exist";
+ public static final String LOG_ENTRY_NOTIFIER = "LogEntryNotifier {0} throws exception";
+ public static final String LOG_ENTRY_ID_CREATED_FROM = "Entry id {0} created from {1}";
+ public static final String LOG_ENTRY_NOT_MATCH_PATH = "Log entry id does not match path variable";
+
+ public static final String LOG_EXISTS_FAILED = "Failed to check if log {0} exists";
+ public static final String LOG_ID_NOT_FOUND = "Log id {0} not found";
+ public static final String LOG_INVALID_LOGBOOKS = "One or more invalid logbook name(s)";
+ public static final String LOG_INVALID_TAGS = "One or more invalid tag name(s)";
+ public static final String LOG_MUST_HAVE_LOGBOOK = "A log entry must specify at least one logbook";
+ public static final String LOG_MUST_HAVE_TITLE = "A log entry must specify a title";
+ public static final String LOG_NOT_ARCHIVED = "Failed to archive log with id {0}";
+ public static final String LOG_NOT_FOUND = "Failed to find log {0}";
+ public static final String LOG_NOT_RETRIEVED = "Failed to retrieve log with id {0}";
+ public static final String LOG_NOT_SAVED = "Failed to save log entry {0}";
+ public static final String LOG_NOT_TITLE = "Log title empty";
+ public static final String LOG_NOT_UPDATED = "Failed to update log entry {0}";
+
+ public static final String LOGS_DELETE_NOT_SUPPORTED = "Deleting log entries is not supported";
+ public static final String LOGS_NOT_FOUND = "Failed to find logs {0}";
+ public static final String LOGS_RETRIEVE_ALL_NOT_SUPPORTED = "Retrieving all log entries is not supported. Use Search with scroll";
+ public static final String LOGS_SEARCH_NOT_COMPLETED = "Failed to complete search for archived logs";
+
+ public static final String PROPERTY_ATTRIBUTE_DELETE = "Deleted property attribute {0}";
+ public static final String PROPERTY_ATTRIBUTE_CANNOT_DELETE = "Cannot delete attribute {0} from property {1} as the property does not exist";
+ public static final String PROPERTY_DELETE = "Deleted property {0}";
+ public static final String PROPERTY_EXISTS_FAILED = "Failed to check if property {0} exists";
+ public static final String PROPERTY_NAME_CANNOT_BE_NULL_OR_EMPTY = "The property name cannot be null or empty {0}";
+ public static final String PROPERTY_NOT_EXISTS = "The property {0} does not exist";
+ public static final String PROPERTY_NOT_CREATED = "Failed to create property {0}";
+ public static final String PROPERTY_NOT_DELETED = "Failed to delete property {0}";
+ public static final String PROPERTY_NOT_FOUND = "Failed to find property {0}";
+
+ public static final String PROPERTIES_DELETE_ALL_NOT_ALLOWED = "Deleting all properties is not allowed";
+ public static final String PROPERTIES_NOT_CREATED = "Failed to create properties {0}";
+ public static final String PROPERTIES_NOT_FOUND = "Failed to find properties";
+ public static final String PROPERTIES_NOT_FOUND_1 = "Failed to find properties {0}";
+
+ public static final String TAG_DELETE = "Deleted tag {0}";
+ public static final String TAG_EXISTS_FAILED = "Failed to check if tag {0} exists";
+ public static final String TAG_INVALID = "Tag {0} is invalid";
+ public static final String TAG_NAME_CANNOT_BE_NULL_OR_EMPTY = "The tag name cannot be null or empty {0}";
+ public static final String TAG_NOT_EXISTS = "The tag {0} does not exist";
+ public static final String TAG_NOT_CREATED = "Failed to create tag {0}";
+ public static final String TAG_NOT_DELETED = "Failed to delete tag {0}";
+ public static final String TAG_NOT_FOUND = "Failed to find tag {0}";
+
+ public static final String TAGS_DELETE_ALL_NOT_ALLOWED = "Deleting all tags is not allowed";
+ public static final String TAGS_NOT_CREATED = "Failed to create tags {0}";
+ public static final String TAGS_NOT_FOUND = "Failed to find tags";
+ public static final String TAGS_NOT_FOUND_1 = "Failed to find tags {0}";
+
+ /**
+ * This class is not to be instantiated.
+ */
+ private TextUtil() {
+ throw new IllegalStateException("Utility class");
+ }
+
+}
diff --git a/src/main/java/org/phoebus/olog/WebSecurityConfig.java b/src/main/java/org/phoebus/olog/WebSecurityConfig.java
index 051c0d3..b765ca8 100644
--- a/src/main/java/org/phoebus/olog/WebSecurityConfig.java
+++ b/src/main/java/org/phoebus/olog/WebSecurityConfig.java
@@ -22,7 +22,6 @@
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabase;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType;
-import org.springframework.ldap.core.support.LdapContextSource;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.authentication.configurers.ldap.LdapAuthenticationProviderConfigurer;
diff --git a/src/main/java/org/phoebus/olog/entity/Attachment.java b/src/main/java/org/phoebus/olog/entity/Attachment.java
index 62241bd..b66c3e5 100644
--- a/src/main/java/org/phoebus/olog/entity/Attachment.java
+++ b/src/main/java/org/phoebus/olog/entity/Attachment.java
@@ -8,11 +8,10 @@
import org.springframework.core.io.InputStreamSource;
import com.fasterxml.jackson.annotation.JsonIgnore;
-import org.springframework.data.mongodb.core.mapping.Document;
/**
* An object describing a log entry attachment.
- *
+ *
* @author Kunal Shroff
*
*/
@@ -66,7 +65,7 @@ public Attachment(String id, InputStreamSource attachment, String filename, Stri
/**
* Getter for attachment id
- *
+ *
* @return attachment id
*/
public String getId()
@@ -76,7 +75,7 @@ public String getId()
/**
* Setter for attachment id
- *
+ *
* @param id - the id for the attachment
*/
public void setId(String id)
diff --git a/src/main/java/org/phoebus/olog/entity/Property.java b/src/main/java/org/phoebus/olog/entity/Property.java
index ddc699f..0eb5cf2 100644
--- a/src/main/java/org/phoebus/olog/entity/Property.java
+++ b/src/main/java/org/phoebus/olog/entity/Property.java
@@ -139,9 +139,9 @@ public Set getAttributes() {
*/
public Set getAttribute(String name)
{
- return attributes.stream().filter(attr -> {
- return name.equals(attr.getName());
- }).collect(Collectors.toSet());
+ return attributes.stream().filter(attr ->
+ name.equals(attr.getName())
+ ).collect(Collectors.toSet());
}
/**
diff --git a/src/main/java/org/phoebus/olog/entity/SearchResult.java b/src/main/java/org/phoebus/olog/entity/SearchResult.java
index a03dc8f..fe8c637 100644
--- a/src/main/java/org/phoebus/olog/entity/SearchResult.java
+++ b/src/main/java/org/phoebus/olog/entity/SearchResult.java
@@ -18,8 +18,6 @@
package org.phoebus.olog.entity;
-import com.fasterxml.jackson.annotation.JsonCreator;
-
import java.util.List;
public class SearchResult {
diff --git a/src/main/java/org/phoebus/olog/security/SessionFilter.java b/src/main/java/org/phoebus/olog/security/SessionFilter.java
index b886287..877eb22 100644
--- a/src/main/java/org/phoebus/olog/security/SessionFilter.java
+++ b/src/main/java/org/phoebus/olog/security/SessionFilter.java
@@ -20,6 +20,7 @@
import com.fasterxml.jackson.databind.ObjectMapper;
+import org.phoebus.olog.TextUtil;
import org.phoebus.olog.WebSecurityConfig;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
@@ -41,6 +42,7 @@
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
+import java.text.MessageFormat;
import java.time.Instant;
import java.util.Base64;
import java.util.List;
@@ -108,8 +110,7 @@ public void doFilter(ServletRequest request, ServletResponse response, FilterCha
SecurityContextHolder.getContext().setAuthentication(authentication);
} catch (AuthenticationException e) {
Logger.getLogger(SessionFilter.class.getName())
- .log(Level.FINE, String.format("User %s not authenticated through authorization header",
- usernameAndPassword[0]));
+ .log(Level.FINE, MessageFormat.format(TextUtil.USER_NOT_AUTHENTICATED_THROUGH_AUTHORIZATION_HEADER, usernameAndPassword[0]));
}
}
}
diff --git a/src/main/java/org/phoebus/util/time/TimestampFormats.java b/src/main/java/org/phoebus/util/time/TimestampFormats.java
index 3ca7b1e..9b54d76 100644
--- a/src/main/java/org/phoebus/util/time/TimestampFormats.java
+++ b/src/main/java/org/phoebus/util/time/TimestampFormats.java
@@ -28,36 +28,36 @@
* @author Kay Kasemir
*/
@SuppressWarnings("nls")
-public class TimestampFormats
-{
- final private static ZoneId zone = ZoneId.systemDefault();
- final private static String FULL_PATTERN = "yyyy-MM-dd HH:mm:ss.nnnnnnnnn";
- final private static String MILLI_PATTERN = "yyyy-MM-dd HH:mm:ss.SSS";
- final private static String SECONDS_PATTERN = "yyyy-MM-dd HH:mm:ss";
- final private static String DATETIME_PATTERN = "yyyy-MM-dd HH:mm";
- final private static String DATE_PATTERN = "yyyy-MM-dd";
- final private static String TIME_PATTERN = "HH:mm:ss";
+public class TimestampFormats {
+
+ private static final ZoneId zone = ZoneId.systemDefault();
+ private static final String FULL_PATTERN = "yyyy-MM-dd HH:mm:ss.nnnnnnnnn";
+ private static final String MILLI_PATTERN = "yyyy-MM-dd HH:mm:ss.SSS";
+ private static final String SECONDS_PATTERN = "yyyy-MM-dd HH:mm:ss";
+ private static final String DATETIME_PATTERN = "yyyy-MM-dd HH:mm";
+ private static final String DATE_PATTERN = "yyyy-MM-dd";
+ private static final String TIME_PATTERN = "HH:mm:ss";
/** Time stamp format for 'full' time stamp */
- final public static DateTimeFormatter FULL_FORMAT= DateTimeFormatter.ofPattern(FULL_PATTERN).withZone(zone);
+ public static final DateTimeFormatter FULL_FORMAT= DateTimeFormatter.ofPattern(FULL_PATTERN).withZone(zone);
/** Time stamp format for time stamp down to milliseconds */
- final public static DateTimeFormatter MILLI_FORMAT= DateTimeFormatter.ofPattern(MILLI_PATTERN).withZone(zone);
+ public static final DateTimeFormatter MILLI_FORMAT= DateTimeFormatter.ofPattern(MILLI_PATTERN).withZone(zone);
/** Time stamp format for time stamp up to seconds, but not nanoseconds */
- final public static DateTimeFormatter SECONDS_FORMAT = DateTimeFormatter.ofPattern(SECONDS_PATTERN).withZone(zone);
+ public static final DateTimeFormatter SECONDS_FORMAT = DateTimeFormatter.ofPattern(SECONDS_PATTERN).withZone(zone);
/** Time stamp format for time date and time, no seconds */
- final public static DateTimeFormatter DATETIME_FORMAT = DateTimeFormatter.ofPattern(DATETIME_PATTERN).withZone(zone);
+ public static final DateTimeFormatter DATETIME_FORMAT = DateTimeFormatter.ofPattern(DATETIME_PATTERN).withZone(zone);
/** Time stamp format for time stamp up to seconds, but no date */
- final public static DateTimeFormatter TIME_FORMAT = DateTimeFormatter.ofPattern(TIME_PATTERN).withZone(zone);
+ public static final DateTimeFormatter TIME_FORMAT = DateTimeFormatter.ofPattern(TIME_PATTERN).withZone(zone);
/** Time stamp format for date, no time */
- final public static DateTimeFormatter DATE_FORMAT = DateTimeFormatter.ofPattern(DATE_PATTERN).withZone(zone);
+ public static final DateTimeFormatter DATE_FORMAT = DateTimeFormatter.ofPattern(DATE_PATTERN).withZone(zone);
// Internal
- final private static DateTimeFormatter MONTH_FORMAT = DateTimeFormatter.ofPattern("MM-dd HH:mm").withZone(zone);
+ private static final DateTimeFormatter MONTH_FORMAT = DateTimeFormatter.ofPattern("MM-dd HH:mm").withZone(zone);
/** Format date and time in a 'compact' way.
*
@@ -68,30 +68,26 @@ public class TimestampFormats
* @param timestamp {@link Instant}
* @return Date and time of the data in preferred text format
*/
- public static String formatCompactDateTime(final Instant timestamp)
- {
+ public static String formatCompactDateTime(final Instant timestamp) {
if (timestamp == null)
return "?";
final LocalDateTime now = LocalDateTime.now();
final LocalDateTime local = LocalDateTime.ofInstant(timestamp, zone);
- if (now.getYear() == local.getYear())
- {
+ if (now.getYear() == local.getYear()) {
// Same day, show time down to HH:mm:ss
if (now.getDayOfYear() == local.getDayOfYear())
return TIME_FORMAT.format(timestamp);
else
// Different day, same year, show month, day, down to minutes
return MONTH_FORMAT.format(timestamp);
- }
- else
+ } else
// Different year, show yyyy-MM-dd";
return DATE_FORMAT.format(timestamp);
}
- private static final DateTimeFormatter absolute_parsers[] = new DateTimeFormatter[]
- {
+ private static final DateTimeFormatter absolute_parsers[] = new DateTimeFormatter[] {
TimestampFormats.FULL_FORMAT,
TimestampFormats.MILLI_FORMAT,
TimestampFormats.SECONDS_FORMAT,
@@ -103,19 +99,14 @@ public static String formatCompactDateTime(final Instant timestamp)
* @param text Text with date, time
* @return {@link Instant} or null
*/
- public static Instant parse(final String text)
- {
- for (DateTimeFormatter format : absolute_parsers)
- {
- try
- {
+ public static Instant parse(final String text) {
+ for (DateTimeFormatter format : absolute_parsers) {
+ try {
// DATE_FORMAT lacks seconds
if (format == DATE_FORMAT)
return Instant.from(DATETIME_FORMAT.parse(text + " 00:00"));
return Instant.from(format.parse(text));
- }
- catch (Throwable ex)
- {
+ } catch (Throwable ex) {
// Ignore
}
}
diff --git a/src/test/java/org/phoebus/olog/AttachmentRepositoryIT.java b/src/test/java/org/phoebus/olog/AttachmentRepositoryIT.java
index 87e3efa..11beabe 100644
--- a/src/test/java/org/phoebus/olog/AttachmentRepositoryIT.java
+++ b/src/test/java/org/phoebus/olog/AttachmentRepositoryIT.java
@@ -28,7 +28,7 @@
@ContextConfiguration(classes = ElasticConfig.class)
@SuppressWarnings("unused")
@TestPropertySource(locations = "classpath:test_application.properties")
-public class AttachmentRepositoryIT {
+class AttachmentRepositoryIT {
@Autowired
private GridFsTemplate gridFsTemplate;
@Autowired
@@ -43,7 +43,7 @@ public class AttachmentRepositoryIT {
* Test the creation of a image attachment
*/
@Test
- public void createImageAttachment() {
+ void createImageAttachment() {
try {
File testFile = new File("src/test/resources/Tulips.jpg");
MockMultipartFile mock;
@@ -75,7 +75,7 @@ public void createImageAttachment() {
* Test the creation of a simple text attachment
*/
@Test
- public void createTextAttachment() {
+ void createTextAttachment() {
try {
File testFile = new File("src/test/resources/SampleTextFile_100kb.txt");
MockMultipartFile mock;
@@ -108,7 +108,7 @@ public void createTextAttachment() {
* Test the retrieval of an image attachment
*/
@Test
- public void retrieveImageAttachment() {
+ void retrieveImageAttachment() {
try {
File testFile = new File("src/test/resources/SampleTextFile_100kb.txt");
MockMultipartFile mock;
diff --git a/src/test/java/org/phoebus/olog/AttachmentResourceTest.java b/src/test/java/org/phoebus/olog/AttachmentResourceTest.java
index 493e021..a5d04fe 100644
--- a/src/test/java/org/phoebus/olog/AttachmentResourceTest.java
+++ b/src/test/java/org/phoebus/olog/AttachmentResourceTest.java
@@ -50,13 +50,13 @@
@ContextHierarchy({@ContextConfiguration(classes = {ResourcesTestConfig.class})})
@WebMvcTest(AttachmentResource.class)
@TestPropertySource(locations = "classpath:no_ldap_test_application.properties")
-public class AttachmentResourceTest extends ResourcesTestBase {
+class AttachmentResourceTest extends ResourcesTestBase {
@Autowired
private AttachmentRepository attachmentRepository;
@Test
- public void testGetAttachment() throws Exception {
+ void testGetAttachment() throws Exception {
Attachment attachment = Mockito.mock(Attachment.class);
InputStreamSource inputStreamSource = Mockito.mock(InputStreamSource.class);
when(inputStreamSource.getInputStream()).thenReturn(new ByteArrayInputStream("data".getBytes()));
@@ -71,7 +71,7 @@ public void testGetAttachment() throws Exception {
}
@Test
- public void testGetAttachmentIOException() throws Exception {
+ void testGetAttachmentIOException() throws Exception {
Attachment attachment = Mockito.mock(Attachment.class);
InputStreamSource inputStreamSource = Mockito.mock(InputStreamSource.class);
when(inputStreamSource.getInputStream()).thenThrow(new IOException());
@@ -83,7 +83,7 @@ public void testGetAttachmentIOException() throws Exception {
}
@Test
- public void testGetAttachmentInvalidId() throws Exception {
+ void testGetAttachmentInvalidId() throws Exception {
when(attachmentRepository.findById("invalid")).thenReturn(Optional.empty());
MockHttpServletRequestBuilder request = get("/" + OlogResourceDescriptors.ATTACHMENT_URI + "/invalid");
mockMvc.perform(request).andExpect(status().isNotFound());
diff --git a/src/test/java/org/phoebus/olog/AuthenticationResourceInifiniteSessionTest.java b/src/test/java/org/phoebus/olog/AuthenticationResourceInifiniteSessionTest.java
index 8cb638d..3ec652d 100644
--- a/src/test/java/org/phoebus/olog/AuthenticationResourceInifiniteSessionTest.java
+++ b/src/test/java/org/phoebus/olog/AuthenticationResourceInifiniteSessionTest.java
@@ -49,14 +49,14 @@
@ContextHierarchy({@ContextConfiguration(classes = {AuthenticationResourceTestConfig.class})})
@WebMvcTest(AuthenticationResourceInifiniteSessionTest.class)
@TestPropertySource(locations = "classpath:no_ldap_test_application_infinite_session_duration.properties")
-public class AuthenticationResourceInifiniteSessionTest extends ResourcesTestBase {
+class AuthenticationResourceInifiniteSessionTest extends ResourcesTestBase {
@Autowired
private AuthenticationManager authenticationManager;
@Test
- public void testSuccessfullLogin() throws Exception {
+ void testSuccessfullLogin() throws Exception {
SimpleGrantedAuthority authority = new SimpleGrantedAuthority("ROLE_ADMIN");
Authentication mockAuthentication = mock(Authentication.class);
Set authorities = new HashSet();
diff --git a/src/test/java/org/phoebus/olog/AuthenticationResourceTest.java b/src/test/java/org/phoebus/olog/AuthenticationResourceTest.java
index 0be6b07..39fef3a 100644
--- a/src/test/java/org/phoebus/olog/AuthenticationResourceTest.java
+++ b/src/test/java/org/phoebus/olog/AuthenticationResourceTest.java
@@ -62,7 +62,7 @@
@ContextHierarchy({@ContextConfiguration(classes = {AuthenticationResourceTestConfig.class})})
@WebMvcTest(AuthenticationResourceTest.class)
@TestPropertySource(locations = "classpath:no_ldap_test_application.properties")
-public class AuthenticationResourceTest extends ResourcesTestBase {
+class AuthenticationResourceTest extends ResourcesTestBase {
@Autowired
@@ -72,7 +72,7 @@ public class AuthenticationResourceTest extends ResourcesTestBase {
private int sessionTimeout;
@Test
- public void testSuccessfullLogin() throws Exception {
+ void testSuccessfullLogin() throws Exception {
SimpleGrantedAuthority authority = new SimpleGrantedAuthority("ROLE_ADMIN");
Authentication mockAuthentication = mock(Authentication.class);
Set authorities = new HashSet();
@@ -115,14 +115,13 @@ public void testSuccessfullLogin() throws Exception {
}
@Test
- public void testGetUserWithNoCookie() throws Exception{
+ void testGetUserWithNoCookie() throws Exception {
MockHttpServletRequestBuilder request = get("/user");
mockMvc.perform(request).andExpect(status().isNotFound());
}
@Test
- public void testGetUserNoSession() throws Exception{
-
+ void testGetUserNoSession() throws Exception {
SimpleGrantedAuthority authority = new SimpleGrantedAuthority("ROLE_ADMIN");
Authentication mockAuthentication = mock(Authentication.class);
Set authorities = new HashSet();
@@ -142,7 +141,7 @@ public void testGetUserNoSession() throws Exception{
}
@Test
- public void testSuccessfullFormLogin() throws Exception {
+ void testSuccessfullFormLogin() throws Exception {
SimpleGrantedAuthority authority = new SimpleGrantedAuthority("ROLE_ADMIN");
Authentication mockAuthentication = mock(Authentication.class);
Set authorities = new HashSet();
@@ -159,7 +158,7 @@ public void testSuccessfullFormLogin() throws Exception {
}
@Test
- public void testFailedLogin() throws Exception {
+ void testFailedLogin() throws Exception {
doThrow(new BadCredentialsException("bad")).when(authenticationManager).authenticate(any(Authentication.class));
MockHttpServletRequestBuilder request = post("/" + OLOG_SERVICE + "/login?username=admin&password=badPass");
mockMvc.perform(request).andExpect(status().isUnauthorized());
@@ -167,7 +166,7 @@ public void testFailedLogin() throws Exception {
}
@Test
- public void testLogout() throws Exception {
+ void testLogout() throws Exception {
MockHttpServletRequestBuilder request = get("/" + OLOG_SERVICE + "/logout");
mockMvc.perform(request).andExpect(status().isOk());
diff --git a/src/test/java/org/phoebus/olog/ContentTypeResolvertest.java b/src/test/java/org/phoebus/olog/ContentTypeResolvertest.java
index f0691c1..409f8d7 100644
--- a/src/test/java/org/phoebus/olog/ContentTypeResolvertest.java
+++ b/src/test/java/org/phoebus/olog/ContentTypeResolvertest.java
@@ -24,11 +24,10 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
-public class ContentTypeResolvertest {
+class ContentTypeResolvertest {
@Test
- public void testDetermineMediaType() {
-
+ void testDetermineMediaType() {
assertNull(ContentTypeResolver.determineMediaType(null));
assertNull(ContentTypeResolver.determineMediaType(""));
diff --git a/src/test/java/org/phoebus/olog/HelpResourceTest.java b/src/test/java/org/phoebus/olog/HelpResourceTest.java
index 60d3fdb..19f270c 100644
--- a/src/test/java/org/phoebus/olog/HelpResourceTest.java
+++ b/src/test/java/org/phoebus/olog/HelpResourceTest.java
@@ -30,42 +30,42 @@
@ExtendWith(SpringExtension.class)
@WebMvcTest(LogResource.class)
-public class HelpResourceTest extends ResourcesTestBase{
+class HelpResourceTest extends ResourcesTestBase{
@Test
- public void testGetCheatSheet() throws Exception{
+ void testGetCheatSheet() throws Exception {
MockHttpServletRequestBuilder request = get("/" + OlogResourceDescriptors.HELP_URI + "/CommonmarkCheatsheet")
.header("Accept-Language", "en-US, en;q=0.9, fr;q=0.8, de;q=0.7, *;q=0.5");
mockMvc.perform(request).andExpect(status().isOk());
}
@Test
- public void testGetCheatSheetWithLanguageParameter() throws Exception{
+ void testGetCheatSheetWithLanguageParameter() throws Exception {
MockHttpServletRequestBuilder request = get("/" + OlogResourceDescriptors.HELP_URI + "/CommonmarkCheatsheet?lang=en");
mockMvc.perform(request).andExpect(status().isOk());
}
@Test
- public void testGetSearchHelp() throws Exception{
+ void testGetSearchHelp() throws Exception {
MockHttpServletRequestBuilder request = get("/" + OlogResourceDescriptors.HELP_URI + "/SearchHelp");
mockMvc.perform(request).andExpect(status().isOk());
}
@Test
- public void testGetCheatSheetUnrecognizedAcceptLanguage() throws Exception{
+ void testGetCheatSheetUnrecognizedAcceptLanguage() throws Exception {
MockHttpServletRequestBuilder request = get("/" + OlogResourceDescriptors.HELP_URI + "/CommonmarkCheatsheet")
.header("Accept-Language", "xx-YY");
mockMvc.perform(request).andExpect(status().isOk());
}
@Test
- public void testGetCheatSheetUnsupportedLanguageParameter() throws Exception{
+ void testGetCheatSheetUnsupportedLanguageParameter() throws Exception {
MockHttpServletRequestBuilder request = get("/" + OlogResourceDescriptors.HELP_URI + "/CommonmarkCheatsheet?lang=xx");
mockMvc.perform(request).andExpect(status().isOk());
}
@Test
- public void testGetCheatSheetUnsupportedHelpType() throws Exception{
+ void testGetCheatSheetUnsupportedHelpType() throws Exception {
MockHttpServletRequestBuilder request = get("/" + OlogResourceDescriptors.HELP_URI + "/unsupported");
mockMvc.perform(request).andExpect(status().isNotFound());
}
diff --git a/src/test/java/org/phoebus/olog/LogEntryValidatorTest.java b/src/test/java/org/phoebus/olog/LogEntryValidatorTest.java
index d38ab41..6c77767 100644
--- a/src/test/java/org/phoebus/olog/LogEntryValidatorTest.java
+++ b/src/test/java/org/phoebus/olog/LogEntryValidatorTest.java
@@ -70,7 +70,7 @@ public static void init() {
}
@Test
- public void testValidLogEntry() {
+ void testValidLogEntry() {
when(logbookRepository.findAll()).thenReturn(Arrays.asList(logbook1, logbook2));
when(tagRepository.findAll()).thenReturn(Arrays.asList(tag1, tag2));
@@ -92,7 +92,7 @@ public void testValidLogEntry() {
}
@Test
- public void testInvalidLogbooks() {
+ void testInvalidLogbooks() {
when(logbookRepository.findAll()).thenReturn(Arrays.asList(logbook1, logbook2));
when(tagRepository.findAll()).thenReturn(Arrays.asList(tag1, tag2));
Logbook badLogbook = new Logbook("bad", "owner");
@@ -115,7 +115,7 @@ public void testInvalidLogbooks() {
}
@Test
- public void testNoLogbooks() {
+ void testNoLogbooks() {
when(logbookRepository.findAll()).thenReturn(Arrays.asList(logbook1, logbook2));
when(tagRepository.findAll()).thenReturn(Arrays.asList(tag1, tag2));
@@ -136,7 +136,7 @@ public void testNoLogbooks() {
}
@Test
- public void testInvalidTags() {
+ void testInvalidTags() {
when(logbookRepository.findAll()).thenReturn(Arrays.asList(logbook1, logbook2));
when(tagRepository.findAll()).thenReturn(Arrays.asList(tag1, tag2));
@@ -160,7 +160,7 @@ public void testInvalidTags() {
}
@Test
- public void testInvalidTitle() {
+ void testInvalidTitle() {
when(logbookRepository.findAll()).thenReturn(Arrays.asList(logbook1, logbook2));
when(tagRepository.findAll()).thenReturn(Arrays.asList(tag1, tag2));
diff --git a/src/test/java/org/phoebus/olog/LogEntryValidatorTestConfig.java b/src/test/java/org/phoebus/olog/LogEntryValidatorTestConfig.java
index 155a6f5..85dfd47 100644
--- a/src/test/java/org/phoebus/olog/LogEntryValidatorTestConfig.java
+++ b/src/test/java/org/phoebus/olog/LogEntryValidatorTestConfig.java
@@ -31,12 +31,12 @@
public class LogEntryValidatorTestConfig {
@Bean
- public LogbookRepository logbookRepository(){
+ public LogbookRepository logbookRepository() {
return Mockito.mock(LogbookRepository.class);
}
@Bean
- public TagRepository tagRepository(){
+ public TagRepository tagRepository() {
return Mockito.mock(TagRepository.class);
}
@@ -46,7 +46,7 @@ public ElasticsearchClient client() {
}
@Bean
- public LogEntryValidator logEntryValidator(){
+ public LogEntryValidator logEntryValidator() {
return new LogEntryValidator();
}
}
diff --git a/src/test/java/org/phoebus/olog/LogRepositoryIT.java b/src/test/java/org/phoebus/olog/LogRepositoryIT.java
index 1901479..dd22a0e 100644
--- a/src/test/java/org/phoebus/olog/LogRepositoryIT.java
+++ b/src/test/java/org/phoebus/olog/LogRepositoryIT.java
@@ -62,7 +62,7 @@
@ContextConfiguration(classes = ElasticConfig.class)
@TestPropertySource(locations = "classpath:test_application.properties")
@SuppressWarnings("unused")
-public class LogRepositoryIT {
+class LogRepositoryIT {
@Autowired
@@ -125,7 +125,7 @@ public class LogRepositoryIT {
* @throws IOException
*/
@Test
- public void createLog() throws IOException {
+ void createLog() throws IOException {
try {
logbookRepository.save(TEST_LOGBOOK_1);
tagRepository.save(TEST_TAG_1);
@@ -170,7 +170,7 @@ public void createLog() throws IOException {
* @throws IOException
*/
@Test
- public void createLogWithEvents() throws IOException {
+ void createLogWithEvents() throws IOException {
try {
logbookRepository.save(TEST_LOGBOOK_1);
tagRepository.save(TEST_TAG_1);
@@ -204,7 +204,7 @@ public void createLogWithEvents() throws IOException {
* @throws IOException
*/
@Test
- public void createLogWithAttachment() throws IOException {
+ void createLogWithAttachment() throws IOException {
logbookRepository.save(TEST_LOGBOOK_1);
tagRepository.save(TEST_TAG_1);
propertyRepository.save(TEST_PROPERTY_1);
@@ -254,7 +254,7 @@ public void createLogWithAttachment() throws IOException {
* @throws IOException
*/
@Test
- public void createLogs(){
+ void createLogs() {
logbookRepository.save(TEST_LOGBOOK_1);
tagRepository.save(TEST_TAG_1);
propertyRepository.save(TEST_PROPERTY_1);
@@ -287,7 +287,7 @@ public void createLogs(){
* @throws IOException
*/
@Test
- public void archiveLog() throws IOException {
+ void archiveLog() throws IOException {
try {
logbookRepository.save(TEST_LOGBOOK_1);
tagRepository.save(TEST_TAG_1);
@@ -325,7 +325,7 @@ public void archiveLog() throws IOException {
* @throws IOException
*/
@Test
- public void archiveLogs() throws IOException {
+ void archiveLogs() throws IOException {
try {
logbookRepository.save(TEST_LOGBOOK_1);
tagRepository.save(TEST_TAG_1);
@@ -373,7 +373,7 @@ public void archiveLogs() throws IOException {
* @throws IOException
*/
@Test
- public void updateLog() throws IOException {
+ void updateLog() throws IOException {
try {
logbookRepository.save(TEST_LOGBOOK_1);
tagRepository.save(TEST_TAG_1);
@@ -406,8 +406,8 @@ public void updateLog() throws IOException {
}
@Test
- public void checkLogExists() throws IOException {
- // check for non existing log entry
+ void checkLogExists() throws IOException {
+ // check for non existing log entry
assertFalse(logRepository.existsById("123456789"), "Failed to check non existance of log entry 123456789");
// check for an existing log entry
@@ -422,7 +422,7 @@ public void checkLogExists() throws IOException {
@Test
- public void findLogsById() throws IOException {
+ void findLogsById() throws IOException {
// check for an existing log entry
Log log = Log.LogBuilder.createLog("This is a test entry").owner(TEST_OWNER).withLogbook(TEST_LOGBOOK_1).build();
Log createdLog = logRepository.save(log);
@@ -434,13 +434,13 @@ public void findLogsById() throws IOException {
}
@Test
- public void findLogsByNonExistingId() throws IOException {
- // check for non existing log entry
+ void findLogsByNonExistingId() throws IOException {
+ // check for non existing log entry
assertFalse(logRepository.existsById("123456789"), "Failed to check non existance of log entry 123456789");
}
@Test
- public void findLogsByIds() throws IOException {
+ void findLogsByIds() throws IOException {
// check for an existing log entry
Log log1 = Log.LogBuilder.createLog("This is a test entry").owner(TEST_OWNER).withLogbook(TEST_LOGBOOK_1).build();
Log log2 = Log.LogBuilder.createLog("This is a test entry").owner(TEST_OWNER).withLogbook(TEST_LOGBOOK_1).build();
diff --git a/src/test/java/org/phoebus/olog/LogRepositorySearchIT.java b/src/test/java/org/phoebus/olog/LogRepositorySearchIT.java
index f0c80fe..cf47e19 100644
--- a/src/test/java/org/phoebus/olog/LogRepositorySearchIT.java
+++ b/src/test/java/org/phoebus/olog/LogRepositorySearchIT.java
@@ -1,5 +1,5 @@
/**
- *
+ *
*/
package org.phoebus.olog;
@@ -41,8 +41,7 @@
@TestExecutionListeners(listeners = {LogRepositorySearchIT.class})
@ContextConfiguration(classes = ElasticConfig.class)
@TestPropertySource(locations = "classpath:test_application.properties")
-public class LogRepositorySearchIT implements TestExecutionListener
-{
+class LogRepositorySearchIT implements TestExecutionListener {
private static LogRepository logRepository;
@@ -51,10 +50,10 @@ public class LogRepositorySearchIT implements TestExecutionListener
private static final Logbook testLogbook1 = new Logbook("testLogbook1", testOwner1, State.Active);
private static final Logbook testLogbook2 = new Logbook("testLogbook2", testOwner1, State.Active);
-
+
private static final Tag testTag1 = new Tag("testTag1", State.Active);
private static final Tag testTag2= new Tag("testTag2", State.Active);
-
+
private static final Event event1 = new Event("testEvent1", Instant.now().minusSeconds(3600));
private static final Event event2 = new Event("testEvent2", Instant.now().minusSeconds(2*3600));
@@ -65,7 +64,7 @@ public class LogRepositorySearchIT implements TestExecutionListener
testOwner1,
State.Active,
new HashSet<>(List.of(testAttribute1, testAttribute2)));
-
+
private static Property testProperty2 = new Property("testProperty2",
testOwner1,
@@ -76,7 +75,7 @@ public class LogRepositorySearchIT implements TestExecutionListener
* Search by title
*/
@Test
- public void searchByTitle(){
+ void searchByTitle() {
MultiValueMap searchParameters = new LinkedMultiValueMap<>();
searchParameters.put("title", List.of("title2"));
List foundLogs = logRepository.search(searchParameters).getLogs();
@@ -98,7 +97,7 @@ public void searchByTitle(){
assertTrue(
foundLogs.size() == 2 && foundLogs.contains(createdLog1) && foundLogs.contains(createdLog2),
"Failed to search for log entries based on title.");
-
+
// check case insensitive searches
searchParameters = new LinkedMultiValueMap<>();
searchParameters.put("title", List.of("TITLE2"));
@@ -112,8 +111,7 @@ public void searchByTitle(){
* Search for log entries based on the level
*/
@Test
- public void searchByLevel()
- {
+ void searchByLevel() {
MultiValueMap searchParameters = new LinkedMultiValueMap<>();
searchParameters.put("level", List.of("level2"));
List foundLogs = logRepository.search(searchParameters).getLogs();
@@ -140,8 +138,7 @@ public void searchByLevel()
* Search for a particular word
*/
@Test
- public void searchByWord()
- {
+ void searchByWord() {
MultiValueMap searchParameters = new LinkedMultiValueMap<>();
searchParameters.put("desc", List.of("quick"));
List foundLogs = logRepository.search(searchParameters).getLogs();
@@ -160,8 +157,7 @@ public void searchByWord()
* Search for a particular word with wildcards
*/
@Test
- public void searchByWordWithWildcards()
- {
+ void searchByWordWithWildcards() {
MultiValueMap searchParameters = new LinkedMultiValueMap<>();
searchParameters.put("desc", List.of("jump*"));
List foundLogs = logRepository.search(searchParameters).getLogs();
@@ -169,13 +165,12 @@ public void searchByWordWithWildcards()
foundLogs.size() == 2 && foundLogs.contains(createdLog1) && foundLogs.contains(createdLog2),
"Failed to search for log entries based on a single keyword.");
}
-
+
/**
* Search for a particular set of words, the search is not sensitive to the order of the words
*/
@Test
- public void searchByWords()
- {
+ void searchByWords() {
MultiValueMap searchParameters = new LinkedMultiValueMap<>();
searchParameters.put("desc", List.of("brown quick"));
List foundLogs = logRepository.search(searchParameters).getLogs();
@@ -189,16 +184,15 @@ public void searchByWords()
}
/**
- *
+ *
*/
@Test
- public void searchByOrderedWords()
- {
+ void searchByOrderedWords() {
MultiValueMap searchParameters = new LinkedMultiValueMap<>();
searchParameters.put("phrase", List.of("brown quick"));
List foundLogs = logRepository.search(searchParameters).getLogs();
assertEquals(0, foundLogs.size(), "Failed to search for log entries based on exact ordered match of key words, expected 0 but found " + foundLogs.size());
-
+
searchParameters.put("phrase", List.of("quick brown"));
foundLogs = logRepository.search(searchParameters).getLogs();
assertTrue(
@@ -210,8 +204,7 @@ public void searchByOrderedWords()
* Search for a log entries based on owner
*/
@Test
- public void searchByOwner()
- {
+ void searchByOwner() {
MultiValueMap searchParameters = new LinkedMultiValueMap<>();
searchParameters.put("owner", List.of(testOwner1));
List foundLogs = logRepository.search(searchParameters).getLogs();
@@ -230,8 +223,7 @@ public void searchByOwner()
* Search for log entries based on the tag/s attached to it
*/
@Test
- public void searchByTags()
- {
+ void searchByTags() {
// simple search based on the tag name
MultiValueMap searchParameters = new LinkedMultiValueMap<>();
searchParameters.put("tags", List.of(testTag1.getName()));
@@ -261,8 +253,7 @@ public void searchByTags()
* Search for log entries based on the logbook/s attached to it
*/
@Test
- public void searchByLogbooks()
- {
+ void searchByLogbooks() {
// simple search based on the logbook name
MultiValueMap searchParameters = new LinkedMultiValueMap<>();
searchParameters.put("logbooks", List.of(testLogbook1.getName()));
@@ -289,9 +280,7 @@ public void searchByLogbooks()
}
@Test
- public void searchByPropertyName()
- {
-
+ void searchByPropertyName() {
// simple search based on the property name
MultiValueMap searchParameters = new LinkedMultiValueMap<>();
searchParameters.put("properties", List.of(testProperty1.getName()));
@@ -319,9 +308,7 @@ public void searchByPropertyName()
}
@Test
- public void searchByPropertyAttribute()
- {
-
+ void searchByPropertyAttribute() {
// simple search based on the property attribute
MultiValueMap searchParameters = new LinkedMultiValueMap<>();
searchParameters.put("properties", List.of(testProperty1.getName() + "." + testAttribute1.getName()));
@@ -344,7 +331,7 @@ public void searchByPropertyAttribute()
assertTrue(
foundLogs.size() == 1 && foundLogs.contains(createdLog1),
"Failed to search for log entries based on logbook names with wildcard cahrs : testLogbook*");
-
+
// search based on a property name and attribute name with wildcards
searchParameters.put("properties", List.of("testProperty*.testAttribute*"));
foundLogs = logRepository.search(searchParameters).getLogs();
@@ -358,11 +345,8 @@ public void searchByPropertyAttribute()
assertEquals(0, foundLogs.size(), "Failed to search for log entries based on logbook names with wildcard cahrs : testLogbook*");
}
-
@Test
- public void searchByPropertyAttributeValue()
- {
-
+ void searchByPropertyAttributeValue() {
// simple search based on the property attribute
MultiValueMap searchParameters = new LinkedMultiValueMap<>();
searchParameters.put("properties", List.of(testProperty1.getName() + "." + testAttribute1.getName() + ".log1"));
@@ -389,7 +373,7 @@ public void searchByPropertyAttributeValue()
assertTrue(
foundLogs.size() == 1 && foundLogs.contains(createdLog1),
"Failed to search for log entries based on logbook names with wildcard cahrs : testLogbook*");
-
+
// search based on a property name and attribute name with wildcards
searchParameters.put("properties", List.of("testProperty*.testAttribute*.log*"));
foundLogs = logRepository.search(searchParameters).getLogs();
@@ -410,8 +394,7 @@ public void searchByPropertyAttributeValue()
}
@Test
- public void searchByTime()
- {
+ void searchByTime() {
// simple search based on the start and end time
MultiValueMap searchParameters = new LinkedMultiValueMap<>();
@@ -424,8 +407,7 @@ public void searchByTime()
}
@Test
- public void searchByEventTime()
- {
+ void searchByEventTime() {
// simple search based on events that occured between the start and end time
MultiValueMap searchParameters = new LinkedMultiValueMap<>();
@@ -442,8 +424,7 @@ public void searchByEventTime()
}
@Test
- public void searchByMultipleKeywords()
- {
+ void searchByMultipleKeywords() {
// search for entries that satisfy all the search conditions.
// Case 1: log entries matches the description, tag, logbook
// expected result: only one log entry should match
@@ -467,7 +448,7 @@ public void searchByMultipleKeywords()
foundLogs = logRepository.search(searchParameters).getLogs();
assertEquals(0, foundLogs.size(), "Failed to search for log entries based on desc, tag, and logbook");
-
+
// Case 3: log entries matches the description, tag, logbook, and time
// expected result: only one log entry should match
searchParameters = new LinkedMultiValueMap<>();
@@ -489,11 +470,10 @@ public void searchByMultipleKeywords()
/**
* Before running the search tests create the set of log entries to be used for searching
- * @throws InterruptedException
+ * @throws InterruptedException
*/
@Override
- public void beforeTestClass(TestContext testContext) throws InterruptedException
- {
+ public void beforeTestClass(TestContext testContext) throws InterruptedException {
logRepository = (LogRepository) testContext.getApplicationContext().getBean("logRepository");
TagRepository tagRepository = (TagRepository) testContext.getApplicationContext().getBean("tagRepository");
LogbookRepository logbookRepository = (LogbookRepository) testContext.getApplicationContext().getBean("logbookRepository");
diff --git a/src/test/java/org/phoebus/olog/LogResourceIT.java b/src/test/java/org/phoebus/olog/LogResourceIT.java
index dc613a1..cbc26c3 100644
--- a/src/test/java/org/phoebus/olog/LogResourceIT.java
+++ b/src/test/java/org/phoebus/olog/LogResourceIT.java
@@ -33,7 +33,7 @@
@ContextConfiguration(classes = {LogResource.class, LogRepository.class, ElasticConfig.class, GridFsOperations.class})
@TestPropertySource(locations = "classpath:test_application.properties")
@SuppressWarnings("unused")
-public class LogResourceIT {
+class LogResourceIT {
@Autowired
LogResource logResource;
@@ -58,7 +58,7 @@ public class LogResourceIT {
private String ES_LOG_TYPE;
@Test
- public void retrieveAttachment() {
+ void retrieveAttachment() {
File testFile = new File("src/test/resources/SampleTextFile_100kb.txt");
try {
diff --git a/src/test/java/org/phoebus/olog/LogResourceTest.java b/src/test/java/org/phoebus/olog/LogResourceTest.java
index 63d0992..f61fb6d 100644
--- a/src/test/java/org/phoebus/olog/LogResourceTest.java
+++ b/src/test/java/org/phoebus/olog/LogResourceTest.java
@@ -40,8 +40,6 @@
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.mock.web.MockMultipartFile;
-import org.springframework.mock.web.MockMultipartHttpServletRequest;
-import org.springframework.mock.web.MockPart;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.ContextHierarchy;
import org.springframework.test.context.TestPropertySource;
@@ -51,12 +49,8 @@
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
-import org.springframework.web.multipart.MultipartHttpServletRequest;
-import org.springframework.web.multipart.MultipartRequest;
-import org.springframework.web.multipart.support.StandardMultipartHttpServletRequest;
import org.springframework.web.server.ResponseStatusException;
-import javax.servlet.http.Part;
import java.time.Instant;
import java.util.Arrays;
import java.util.HashSet;
@@ -139,7 +133,7 @@ public static void init() {
}
@Test
- public void testGetLogById() throws Exception {
+ void testGetLogById() throws Exception {
when(logRepository.findById("1")).thenAnswer(invocationOnMock -> Optional.of(log1));
MockHttpServletRequestBuilder request = get("/" + OlogResourceDescriptors.LOG_RESOURCE_URI + "/1");
@@ -152,7 +146,7 @@ public void testGetLogById() throws Exception {
}
@Test
- public void testGetLogByIdRepositoryThrowsException() throws Exception {
+ void testGetLogByIdRepositoryThrowsException() throws Exception {
when(logRepository.findById("1")).thenThrow(new ResponseStatusException(HttpStatus.NOT_FOUND, ""));
MockHttpServletRequestBuilder request = get("/" + OlogResourceDescriptors.LOG_RESOURCE_URI + "/1");
@@ -162,7 +156,7 @@ public void testGetLogByIdRepositoryThrowsException() throws Exception {
}
@Test
- public void testFindLogs() throws Exception {
+ void testFindLogs() throws Exception {
MultiValueMap map = new LinkedMultiValueMap<>();
map.put("a", List.of("b"));
@@ -184,7 +178,7 @@ public void testFindLogs() throws Exception {
}
@Test
- public void testSearchLogs() throws Exception {
+ void testSearchLogs() throws Exception {
MultiValueMap map = new LinkedMultiValueMap<>();
map.put("a", List.of("b"));
@@ -202,7 +196,7 @@ public void testSearchLogs() throws Exception {
}
@Test
- public void testSearchLogsUnsupportedTemporals() throws Exception {
+ void testSearchLogsUnsupportedTemporals() throws Exception {
MultiValueMap map = new LinkedMultiValueMap<>();
map.put("start", List.of("2 years"));
@@ -221,7 +215,7 @@ public void testSearchLogsUnsupportedTemporals() throws Exception {
}
@Test
- public void testCreateLogUnauthorized() throws Exception {
+ void testCreateLogUnauthorized() throws Exception {
MockHttpServletRequestBuilder request = put("/" + OlogResourceDescriptors.LOG_RESOURCE_URI)
.content(objectMapper.writeValueAsString(log1))
.contentType(JSON);
@@ -229,8 +223,7 @@ public void testCreateLogUnauthorized() throws Exception {
}
@Test
- public void testCreateLog() throws Exception {
-
+ void testCreateLog() throws Exception {
Log log = LogBuilder.createLog()
.id(1L)
.owner("user")
@@ -262,8 +255,7 @@ public void testCreateLog() throws Exception {
* @throws Exception
*/
@Test
- public void testUpdateExisting() throws Exception {
-
+ void testUpdateExisting() throws Exception {
Property property1 = new Property();
property1.setName("prop1");
property1.addAttributes(new Attribute("name1", "value1"));
@@ -293,8 +285,7 @@ public void testUpdateExisting() throws Exception {
}
@Test
- public void testUpdateBadRequest() throws Exception {
-
+ void testUpdateBadRequest() throws Exception {
Property property1 = new Property();
property1.setName("prop1");
property1.addAttributes(new Attribute("name1", "value1"));
@@ -327,14 +318,14 @@ public void testUpdateBadRequest() throws Exception {
* @throws Exception
*/
@Test
- public void testGetAttachment() throws Exception {
+ void testGetAttachment() throws Exception {
MockHttpServletRequestBuilder request = get("/" + OlogResourceDescriptors.LOG_RESOURCE_URI
+ "/attachments/1/attachmentName");
mockMvc.perform(request).andExpect(status().isOk());
}
@Test
- public void testCreateAttachmentUnauthroized() throws Exception {
+ void testCreateAttachmentUnauthroized() throws Exception {
MockHttpServletRequestBuilder request = put("/" + OlogResourceDescriptors.LOG_RESOURCE_URI
+ "/attachments/1");
mockMvc.perform(request).andExpect(status().isUnauthorized());
@@ -346,8 +337,7 @@ public void testCreateAttachmentUnauthroized() throws Exception {
* @throws Exception
*/
@Test
- public void testCreateAttachment() throws Exception {
-
+ void testCreateAttachment() throws Exception {
when(logRepository.findById("1")).thenReturn(Optional.of(log1));
MockMultipartFile file =
new MockMultipartFile("file", "filename.txt", "text/plain", "some xml".getBytes());
@@ -365,7 +355,7 @@ public void testCreateAttachment() throws Exception {
}
@Test
- public void testCreateLogMultipart() throws Exception{
+ void testCreateLogMultipart() throws Exception {
Attachment attachment = new Attachment();
attachment.setId("attachmentId");
attachment.setFilename("filename1.txt");
@@ -408,7 +398,7 @@ public void testCreateLogMultipart() throws Exception{
}
@Test
- public void testCreateLogMultipartNoAttachments() throws Exception{
+ void testCreateLogMultipartNoAttachments() throws Exception {
Log log = LogBuilder.createLog()
.id(1L)
.owner("user")
@@ -442,7 +432,7 @@ public void testCreateLogMultipartNoAttachments() throws Exception{
}
@Test
- public void testCreateLogMultipartFileAndAttachmentMismatch() throws Exception{
+ void testCreateLogMultipartFileAndAttachmentMismatch() throws Exception {
Attachment attachment = new Attachment();
attachment.setId("attachmentId");
attachment.setFilename("filename1.txt");
@@ -486,7 +476,6 @@ public void testCreateLogMultipartFileAndAttachmentMismatch() throws Exception{
reset(logRepository);
}
-
/**
* A matcher used to work around issues with {@link Log#equals(Object)} when using the mocks.
*/
@@ -512,7 +501,7 @@ public boolean matches(Log obj) {
}
@Test
- public void testReplyInvalidLogEntryId() throws Exception {
+ void testReplyInvalidLogEntryId() throws Exception {
when(logbookRepository.findAll()).thenReturn(Arrays.asList(logbook1, logbook2));
when(tagRepository.findAll()).thenReturn(Arrays.asList(tag1, tag2));
when(logRepository.findById("7"))
@@ -526,7 +515,7 @@ public void testReplyInvalidLogEntryId() throws Exception {
}
@Test
- public void testReplyValidLogEntryId() throws Exception {
+ void testReplyValidLogEntryId() throws Exception {
when(logbookRepository.findAll()).thenReturn(Arrays.asList(logbook1, logbook2));
when(tagRepository.findAll()).thenReturn(Arrays.asList(tag1, tag2));
when(logRepository.findById("7"))
@@ -542,7 +531,7 @@ public void testReplyValidLogEntryId() throws Exception {
}
@Test
- public void testGroupNonExistingLogEntryId() throws Exception {
+ void testGroupNonExistingLogEntryId() throws Exception {
when(logRepository.findById("1")).thenReturn(Optional.of(Log.LogBuilder.createLog().build()));
when(logRepository.findById("2")).thenThrow(new ResponseStatusException(HttpStatus.NOT_FOUND, "Not found."));
@@ -558,7 +547,7 @@ public void testGroupNonExistingLogEntryId() throws Exception {
}
@Test
- public void testGroupMultipleGroupIdsFound() throws Exception {
+ void testGroupMultipleGroupIdsFound() throws Exception {
Property logEntryGroupProperty1 = LogEntryGroupHelper.createNewLogEntryProperty();
Log log1 = Log.LogBuilder.createLog().id(1L).setProperties(Set.of(logEntryGroupProperty1)).build();
Property logEntryGroupProperty2 = LogEntryGroupHelper.createNewLogEntryProperty();
@@ -578,7 +567,7 @@ public void testGroupMultipleGroupIdsFound() throws Exception {
}
@Test
- public void testGroupWithExisting1() throws Exception {
+ void testGroupWithExisting1() throws Exception {
Property logEntryGroupProperty1 = LogEntryGroupHelper.createNewLogEntryProperty();
Log log1 = Log.LogBuilder.createLog().id(1L).setProperties(Set.of(logEntryGroupProperty1)).build();
Log log2 = Log.LogBuilder.createLog().id(2L).setProperties(Set.of(logEntryGroupProperty1)).build();
@@ -597,7 +586,7 @@ public void testGroupWithExisting1() throws Exception {
}
@Test
- public void testGroupWithExisting2() throws Exception {
+ void testGroupWithExisting2() throws Exception {
Property logEntryGroupProperty1 = LogEntryGroupHelper.createNewLogEntryProperty();
Log log1 = Log.LogBuilder.createLog().id(1L).setProperties(Set.of(logEntryGroupProperty1)).build();
Log log2 = Log.LogBuilder.createLog().id(2L).build();
@@ -616,7 +605,7 @@ public void testGroupWithExisting2() throws Exception {
}
@Test
- public void testGroupNoExisting() throws Exception {
+ void testGroupNoExisting() throws Exception {
Log log1 = Log.LogBuilder.createLog().id(1L).build();
Log log2 = Log.LogBuilder.createLog().id(2L).build();
when(logRepository.findById("1")).thenReturn(Optional.of(log1));
diff --git a/src/test/java/org/phoebus/olog/LogResourceTestConfig.java b/src/test/java/org/phoebus/olog/LogResourceTestConfig.java
index 7667740..1c3b353 100644
--- a/src/test/java/org/phoebus/olog/LogResourceTestConfig.java
+++ b/src/test/java/org/phoebus/olog/LogResourceTestConfig.java
@@ -49,7 +49,7 @@ public GridFsTemplate gridFsTemplate() {
}
//@Bean
- //public GridFSBucket gridFSBucket(){
+ //public GridFSBucket gridFSBucket() {
// return Mockito.mock(GridFSBucket.class);
//}
diff --git a/src/test/java/org/phoebus/olog/LogSearchUtilTest.java b/src/test/java/org/phoebus/olog/LogSearchUtilTest.java
index 3ec9e43..dc8c2f1 100644
--- a/src/test/java/org/phoebus/olog/LogSearchUtilTest.java
+++ b/src/test/java/org/phoebus/olog/LogSearchUtilTest.java
@@ -33,10 +33,10 @@
import static org.phoebus.olog.LogSearchUtil.MILLI_FORMAT;
@TestPropertySource(locations = "classpath:no_ldap_test_application.properties")
-public class LogSearchUtilTest {
+class LogSearchUtilTest {
@Test
- public void testSortOrder() {
+ void testSortOrder() {
LogSearchUtil logSearchUtil = new LogSearchUtil();
// Test DESC and ASC
@@ -117,8 +117,7 @@ public void testSortOrder() {
}
@Test
- public void checkForInvalidTimeRanges() {
-
+ void checkForInvalidTimeRanges() {
LogSearchUtil logSearchUtil = new LogSearchUtil();
String expectedMessage = "CAUSE: Invalid start and end times";
@@ -136,7 +135,7 @@ public void checkForInvalidTimeRanges() {
}
@Test
- public void testGetSearchTerms(){
+ void testGetSearchTerms() {
LogSearchUtil logSearchUtil = new LogSearchUtil();
String userInput = "";
List parsed = logSearchUtil.getSearchTerms(userInput);
diff --git a/src/test/java/org/phoebus/olog/LogbookRepositoryIT.java b/src/test/java/org/phoebus/olog/LogbookRepositoryIT.java
index fc6501e..49d8df4 100644
--- a/src/test/java/org/phoebus/olog/LogbookRepositoryIT.java
+++ b/src/test/java/org/phoebus/olog/LogbookRepositoryIT.java
@@ -35,7 +35,7 @@
classes = AuthenticationResource.class)
@ContextConfiguration(classes = {LogbookRepository.class, ElasticConfig.class})
@TestPropertySource(locations = "classpath:test_application.properties")
-public class LogbookRepositoryIT {
+class LogbookRepositoryIT {
// Read the elastic index and type from the application.properties
@Value("${elasticsearch.logbook.index:olog_logbooks}")
@@ -59,7 +59,7 @@ public class LogbookRepositoryIT {
* Test the creation of a test logbook
*/
@Test
- public void createLogbook() {
+ void createLogbook() {
try {
logbookRepository.save(testLogbook1);
Optional result = logbookRepository.findById(testLogbook1.getName());
@@ -73,7 +73,7 @@ public void createLogbook() {
* create a set of logbooks
*/
@Test
- public void createLogbooks() {
+ void createLogbooks() {
List logbooks = Arrays.asList(testLogbook1, testLogbook2, testLogbook3, testLogbook4);
try {
List result = new ArrayList<>();
@@ -93,7 +93,7 @@ public void createLogbooks() {
* Test the deletion of a logbook
*/
@Test
- public void deleteLogbook(){
+ void deleteLogbook() {
try {
logbookRepository.save(testLogbook2);
Optional result = logbookRepository.findById(testLogbook2.getName());
@@ -113,7 +113,7 @@ public void deleteLogbook(){
* Delete a set of logbooks
*/
@Test
- public void deteleLogbooks(){
+ void deteleLogbooks() {
List logbooks = Arrays.asList(testLogbook1, testLogbook2, testLogbook3, testLogbook4);
try {
List result = new ArrayList<>();
@@ -137,7 +137,7 @@ public void deteleLogbooks(){
* Find all logbooks that are still Active
*/
@Test
- public void findAllLogbooks(){
+ void findAllLogbooks() {
List logbooks = Arrays.asList(testLogbook1, testLogbook2, testLogbook3, testLogbook4);
try {
logbookRepository.saveAll(logbooks);
@@ -154,7 +154,7 @@ public void findAllLogbooks(){
* Find a logbook with the given Id, the logbook is found irrespective of its State
*/
@Test
- public void findLogbooksById(){
+ void findLogbooksById() {
List logbooks = Arrays.asList(testLogbook1, testLogbook2);
try {
logbookRepository.saveAll(logbooks);
@@ -170,7 +170,7 @@ public void findLogbooksById(){
* Find logbooks with the given Ids, the logbooks are found irrespective of its State
*/
@Test
- public void findAllLogbooksByIds(){
+ void findAllLogbooksByIds() {
List logbooks = Arrays.asList(testLogbook1, testLogbook2, testLogbook3, testLogbook4);
try {
logbookRepository.saveAll(logbooks);
@@ -188,7 +188,7 @@ public void findAllLogbooksByIds(){
}
@Test
- public void checkLogbookExist(){
+ void checkLogbookExist() {
List logbooks = Arrays.asList(testLogbook1, testLogbook2);
try {
logbookRepository.saveAll(logbooks);
@@ -206,7 +206,7 @@ public void checkLogbookExist(){
}
@Test
- public void checkLogbooksExist() {
+ void checkLogbooksExist() {
List logbooks = Arrays.asList(testLogbook1, testLogbook2);
try {
logbookRepository.saveAll(logbooks);
@@ -225,7 +225,6 @@ public void checkLogbooksExist() {
}
}
-
/**
* Cleanup up the logbooks
*
diff --git a/src/test/java/org/phoebus/olog/LogbookResourceTest.java b/src/test/java/org/phoebus/olog/LogbookResourceTest.java
index 709206b..e7ccbf8 100644
--- a/src/test/java/org/phoebus/olog/LogbookResourceTest.java
+++ b/src/test/java/org/phoebus/olog/LogbookResourceTest.java
@@ -75,7 +75,7 @@ public static void init() {
}
@Test
- public void testFindAll() throws Exception {
+ void testFindAll() throws Exception {
when(logbookRepository.findAll()).thenReturn(Arrays.asList(logbook1, logbook2));
MockHttpServletRequestBuilder request = get("/" + OlogResourceDescriptors.LOGBOOK_RESOURCE_URI);
@@ -90,7 +90,7 @@ public void testFindAll() throws Exception {
}
@Test
- public void testFindAllNoLogbooks() throws Exception {
+ void testFindAllNoLogbooks() throws Exception {
when(logbookRepository.findAll()).thenReturn(new ArrayList<>());
MockHttpServletRequestBuilder request = get("/" + OlogResourceDescriptors.LOGBOOK_RESOURCE_URI);
@@ -105,7 +105,7 @@ public void testFindAllNoLogbooks() throws Exception {
}
@Test
- public void testFindLogbookByName() throws Exception {
+ void testFindLogbookByName() throws Exception {
when(logbookRepository.findById("name1")).thenReturn(Optional.of(logbook1));
MockHttpServletRequestBuilder request = get("/" +
@@ -121,7 +121,7 @@ public void testFindLogbookByName() throws Exception {
}
@Test
- public void testCreateLogbookUnauthorized() throws Exception {
+ void testCreateLogbookUnauthorized() throws Exception {
MockHttpServletRequestBuilder request = put("/" +
OlogResourceDescriptors.LOGBOOK_RESOURCE_URI +
"/name1")
@@ -131,7 +131,7 @@ public void testCreateLogbookUnauthorized() throws Exception {
}
@Test
- public void testCreateLogbook() throws Exception {
+ void testCreateLogbook() throws Exception {
Logbook logbookWithWrongOwnerName = new Logbook("name1", "owner1");
when(logbookRepository.save(logbook1)).thenReturn(logbook1);
MockHttpServletRequestBuilder request = put("/" +
@@ -147,7 +147,7 @@ public void testCreateLogbook() throws Exception {
}
@Test
- public void testUpdateLogbooksUnauthorized() throws Exception {
+ void testUpdateLogbooksUnauthorized() throws Exception {
MockHttpServletRequestBuilder request = put("/" +
OlogResourceDescriptors.LOGBOOK_RESOURCE_URI)
.content(objectMapper.writeValueAsString(new ArrayList<>()))
@@ -156,7 +156,7 @@ public void testUpdateLogbooksUnauthorized() throws Exception {
}
@Test
- public void testUpdateLogbooks() throws Exception {
+ void testUpdateLogbooks() throws Exception {
List logbooks = Arrays.asList(logbook1, logbook2);
when(logbookRepository.saveAll(logbooks)).thenReturn(logbooks);
MockHttpServletRequestBuilder request = put("/" +
@@ -174,7 +174,7 @@ public void testUpdateLogbooks() throws Exception {
}
@Test
- public void testDeleteUnauthorized() throws Exception {
+ void testDeleteUnauthorized() throws Exception {
MockHttpServletRequestBuilder request = delete("/" +
OlogResourceDescriptors.LOGBOOK_RESOURCE_URI +
"/name1");
@@ -182,7 +182,7 @@ public void testDeleteUnauthorized() throws Exception {
}
@Test
- public void testDelete() throws Exception {
+ void testDelete() throws Exception {
MockHttpServletRequestBuilder request = delete("/" +
OlogResourceDescriptors.LOGBOOK_RESOURCE_URI +
"/name1")
diff --git a/src/test/java/org/phoebus/olog/PropertiesResourceTest.java b/src/test/java/org/phoebus/olog/PropertiesResourceTest.java
index 63031b4..fb916b3 100644
--- a/src/test/java/org/phoebus/olog/PropertiesResourceTest.java
+++ b/src/test/java/org/phoebus/olog/PropertiesResourceTest.java
@@ -70,7 +70,7 @@ public static void init() {
}
@Test
- public void testFindAll() throws Exception {
+ void testFindAll() throws Exception {
when(propertyRepository.findAll()).thenReturn(Arrays.asList(property1, property2));
MockHttpServletRequestBuilder request = get("/" + OlogResourceDescriptors.PROPERTY_RESOURCE_URI);
@@ -84,7 +84,7 @@ public void testFindAll() throws Exception {
}
@Test
- public void testFindById() throws Exception {
+ void testFindById() throws Exception {
when(propertyRepository.findById("property1")).thenReturn(Optional.of(property1));
MockHttpServletRequestBuilder request = get("/" +
OlogResourceDescriptors.PROPERTY_RESOURCE_URI +
@@ -98,7 +98,7 @@ public void testFindById() throws Exception {
}
@Test
- public void testCreatePropertyUnauthorized() throws Exception {
+ void testCreatePropertyUnauthorized() throws Exception {
MockHttpServletRequestBuilder request = put("/" +
OlogResourceDescriptors.PROPERTY_RESOURCE_URI +
"/property1");
@@ -106,8 +106,7 @@ public void testCreatePropertyUnauthorized() throws Exception {
}
@Test
- public void testCreateProperty() throws Exception {
-
+ void testCreateProperty() throws Exception {
Property property = new Property("property1");
property.setOwner("user");
@@ -126,8 +125,7 @@ public void testCreateProperty() throws Exception {
}
@Test
- public void testUpdatePropertyUnauthoroized() throws Exception {
-
+ void testUpdatePropertyUnauthoroized() throws Exception {
MockHttpServletRequestBuilder request = put("/" +
OlogResourceDescriptors.PROPERTY_RESOURCE_URI)
.session(new MockHttpSession());
@@ -135,8 +133,7 @@ public void testUpdatePropertyUnauthoroized() throws Exception {
}
@Test
- public void testUpdateProperty() throws Exception {
-
+ void testUpdateProperty() throws Exception {
Property property = new Property("property1");
property.setOwner("user");
@@ -156,7 +153,7 @@ public void testUpdateProperty() throws Exception {
}
@Test
- public void testDeleteUnauthorized() throws Exception {
+ void testDeleteUnauthorized() throws Exception {
MockHttpServletRequestBuilder request = delete("/" +
OlogResourceDescriptors.PROPERTY_RESOURCE_URI +
"/property1");
@@ -164,7 +161,7 @@ public void testDeleteUnauthorized() throws Exception {
}
@Test
- public void testDelete() throws Exception {
+ void testDelete() throws Exception {
MockHttpServletRequestBuilder request = delete("/" +
OlogResourceDescriptors.PROPERTY_RESOURCE_URI +
"/property1")
@@ -173,7 +170,6 @@ public void testDelete() throws Exception {
reset(propertyRepository);
}
-
/**
* A matcher used to work around issues with {@link Property#equals(Object)} when using the mocks.
*/
diff --git a/src/test/java/org/phoebus/olog/PropertyRepositoryIT.java b/src/test/java/org/phoebus/olog/PropertyRepositoryIT.java
index ea293f2..13e3301 100644
--- a/src/test/java/org/phoebus/olog/PropertyRepositoryIT.java
+++ b/src/test/java/org/phoebus/olog/PropertyRepositoryIT.java
@@ -38,13 +38,12 @@
classes = AuthenticationResource.class)
@ContextConfiguration(classes = ElasticConfig.class)
@TestPropertySource(locations = "classpath:test_application.properties")
-public class PropertyRepositoryIT {
+class PropertyRepositoryIT {
@Autowired
@Qualifier("client")
ElasticsearchClient client;
-
@Autowired
private PropertyRepository propertyRepository;
@@ -68,7 +67,7 @@ public class PropertyRepositoryIT {
* Test the creation of a test property
*/
@Test
- public void createProperty() {
+ void createProperty() {
propertyRepository.save(testProperty1);
Optional result = propertyRepository.findById(testProperty1.getName());
assertThat("Failed to create Property " + testProperty1,
@@ -82,7 +81,7 @@ public void createProperty() {
* create a set of properties
*/
@Test
- public void createProperties() {
+ void createProperties() {
List properties = Arrays.asList(testProperty1, testProperty2, testProperty3, testProperty4);
List result = new ArrayList<>();
propertyRepository.saveAll(properties).forEach(result::add);
@@ -99,7 +98,7 @@ public void createProperties() {
* Test the deletion of a test property
*/
@Test
- public void deleteProperty() {
+ void deleteProperty() {
propertyRepository.save(testProperty2);
Optional result = propertyRepository.findById(testProperty2.getName());
assertThat("Failed to create Property " + testProperty2,
@@ -118,7 +117,7 @@ public void deleteProperty() {
* Test the deletion of a test property
*/
@Test
- public void deletePropertyAttribute() {
+ void deletePropertyAttribute() {
propertyRepository.save(testProperty2);
Optional result = propertyRepository.findById(testProperty2.getName());
assertThat("Failed to create Property " + testProperty2,
@@ -142,7 +141,7 @@ public void deletePropertyAttribute() {
* delete a set of properties
*/
@Test
- public void deleteproperties() {
+ void deleteproperties() {
List properties = Arrays.asList(testProperty1, testProperty2, testProperty3, testProperty4);
try {
List result = new ArrayList<>();
@@ -163,7 +162,7 @@ public void deleteproperties() {
}
@Test
- public void findAllproperties() {
+ void findAllproperties() {
List properties = Arrays.asList(testProperty1, testProperty2, testProperty3, testProperty4);
try {
propertyRepository.saveAll(properties);
@@ -177,7 +176,7 @@ public void findAllproperties() {
}
@Test
- public void findAllpropertiesByIds() {
+ void findAllpropertiesByIds() {
List properties = Arrays.asList(testProperty1, testProperty2, testProperty3, testProperty4);
try {
propertyRepository.saveAll(properties);
@@ -195,7 +194,7 @@ public void findAllpropertiesByIds() {
}
@Test
- public void findPropertyById() {
+ void findPropertyById() {
List properties = Arrays.asList(testProperty1, testProperty2);
try {
propertyRepository.saveAll(properties);
@@ -208,7 +207,7 @@ public void findPropertyById() {
}
@Test
- public void checkPropertyExists() {
+ void checkPropertyExists() {
List properties = Arrays.asList(testProperty1, testProperty2);
try {
propertyRepository.saveAll(properties);
@@ -226,7 +225,6 @@ public void checkPropertyExists() {
}
}
-
/**
* Clean up the properties
*
diff --git a/src/test/java/org/phoebus/olog/ResourcesTestConfig.java b/src/test/java/org/phoebus/olog/ResourcesTestConfig.java
index 88125c5..6b520a1 100644
--- a/src/test/java/org/phoebus/olog/ResourcesTestConfig.java
+++ b/src/test/java/org/phoebus/olog/ResourcesTestConfig.java
@@ -112,7 +112,7 @@ public GridFSBucket gridFSBucket() {
}
@Bean
- public LogEntryValidator logEntryValidator(){
+ public LogEntryValidator logEntryValidator() {
LogEntryValidator logEntryValidator = Mockito.mock(LogEntryValidator.class);
when(logEntryValidator.supports(Mockito.any(Class.class))).thenReturn(true);
return logEntryValidator;
diff --git a/src/test/java/org/phoebus/olog/ServiceConfigurationResourceTest.java b/src/test/java/org/phoebus/olog/ServiceConfigurationResourceTest.java
index b199bcc..a0d3224 100644
--- a/src/test/java/org/phoebus/olog/ServiceConfigurationResourceTest.java
+++ b/src/test/java/org/phoebus/olog/ServiceConfigurationResourceTest.java
@@ -70,7 +70,7 @@ public static void init() {
}
@Test
- public void testServiceConfiguration() throws Exception {
+ void testServiceConfiguration() throws Exception {
when(logbookRepository.findAll()).thenReturn(Arrays.asList(logbook1, logbook2));
when(tagRepository.findAll()).thenReturn(Arrays.asList(tag1, tag2));
diff --git a/src/test/java/org/phoebus/olog/TagRepositoryIT.java b/src/test/java/org/phoebus/olog/TagRepositoryIT.java
index 762abf2..aa9acb6 100644
--- a/src/test/java/org/phoebus/olog/TagRepositoryIT.java
+++ b/src/test/java/org/phoebus/olog/TagRepositoryIT.java
@@ -37,8 +37,7 @@
@ContextConfiguration(classes = ElasticConfig.class)
@TestPropertySource(locations = "classpath:test_application.properties")
@SuppressWarnings("unused")
-public class TagRepositoryIT {
-
+class TagRepositoryIT {
@Autowired
private TagRepository tagRepository;
@@ -62,7 +61,7 @@ public class TagRepositoryIT {
* @throws IOException
*/
@Test
- public void createTag() throws IOException {
+ void createTag() throws IOException {
tagRepository.save(testTag1);
Optional result = tagRepository.findById(testTag1.getName());
assertThat("Failed to create Tag " + testTag1, result.isPresent() && result.get().equals(testTag1));
@@ -77,7 +76,7 @@ public void createTag() throws IOException {
* @throws IOException
*/
@Test
- public void deleteTag() throws IOException {
+ void deleteTag() throws IOException {
tagRepository.save(testTag2);
Optional result = tagRepository.findById(testTag2.getName());
assertThat("Failed to create Tag " + testTag2, result.isPresent() && result.get().equals(testTag2));
@@ -95,7 +94,7 @@ public void deleteTag() throws IOException {
* create a set of tags
*/
@Test
- public void createTags() {
+ void createTags() {
List tags = Arrays.asList(testTag1, testTag2, testTag3, testTag4);
try {
List result = new ArrayList<>();
@@ -115,7 +114,7 @@ public void createTags() {
* delete a set of tags
*/
@Test
- public void deleteTags() {
+ void deleteTags() {
List tags = Arrays.asList(testTag1, testTag2, testTag3, testTag4);
try {
List result = new ArrayList<>();
@@ -136,7 +135,7 @@ public void deleteTags() {
}
@Test
- public void findAllTags() {
+ void findAllTags() {
List tags = Arrays.asList(testTag1, testTag2, testTag3, testTag4);
try {
tagRepository.saveAll(tags);
@@ -150,7 +149,7 @@ public void findAllTags() {
}
@Test
- public void findAllTagsByIds() throws IOException {
+ void findAllTagsByIds() throws IOException {
List tags = Arrays.asList(testTag1, testTag2, testTag3, testTag4);
try {
tagRepository.saveAll(tags);
@@ -168,12 +167,12 @@ public void findAllTagsByIds() throws IOException {
}
@Test
- public void findAllInactiveTags() {
+ void findAllInactiveTags() {
}
@Test
- public void findTagById() {
+ void findTagById() {
List tags = Arrays.asList(testTag1, testTag2);
try {
tagRepository.saveAll(tags);
@@ -186,7 +185,7 @@ public void findTagById() {
}
@Test
- public void checkTagExists() {
+ void checkTagExists() {
List tags = Arrays.asList(testTag1, testTag2);
try {
tagRepository.saveAll(tags);
diff --git a/src/test/java/org/phoebus/olog/docker/ITTestFixture.java b/src/test/java/org/phoebus/olog/docker/ITTestFixture.java
index 0463726..3a52702 100644
--- a/src/test/java/org/phoebus/olog/docker/ITTestFixture.java
+++ b/src/test/java/org/phoebus/olog/docker/ITTestFixture.java
@@ -1,10 +1,23 @@
/*
* Copyright (C) 2021 European Spallation Source ERIC.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
package org.phoebus.olog.docker;
-import com.fasterxml.jackson.databind.ObjectMapper;
import org.phoebus.olog.entity.Attribute;
import org.phoebus.olog.entity.Event;
import org.phoebus.olog.entity.Log;
@@ -17,11 +30,9 @@
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.time.Instant;
+import java.util.HashSet;
import java.util.List;
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertNotNull;
-import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
/**
@@ -62,6 +73,9 @@ public class ITTestFixture {
static final String SHIFT_END = "Shift End";
// test data
+ static Logbook[] default_logbooks;
+ static Tag[] default_tags;
+ static Property[] default_properties;
static Logbook logbookBuildings;
static Logbook logbookCommunication;
@@ -166,6 +180,14 @@ static void setup() {
// to add items to logs (logbooks, tags, properties, attachments)
// for assert statements
+ default_logbooks = new Logbook[] {
+ new Logbook("operations", "olog-logs", State.Active),
+ new Logbook("controls", null, State.Active)};
+ default_tags = new Tag[] {new Tag("alarm", State.Active)};
+ default_properties = new Property[] {new Property("resource", null, State.Active, new HashSet())};
+ default_properties[0].addAttributes(new Attribute("name", null, State.Active));
+ default_properties[0].addAttributes(new Attribute("file", null, State.Active));
+
setupLogbooks();
setupTags();
setupProperties();
@@ -185,6 +207,10 @@ static void tearDown() {
// not necessary to remove items from logs in order to tear down (logbooks, tags, properties, attachments)
// items can be deleted regardless
+ default_logbooks = null;
+ default_tags = null;
+ default_properties = null;
+
tearDownLogbooks();
tearDownTags();
tearDownProperties();
@@ -417,87 +443,57 @@ private static void setupLogs() {
* Create test fixture, logbooks.
*/
private static void createLogbooks() {
- ObjectMapper mapper = new ObjectMapper();
-
try {
// --------------------------------------------------------------------------------
// clean start
// --------------------------------------------------------------------------------
- String[] response = ITUtil.doGetJson(OlogLogbooksIT.HTTP_IP_PORT_OLOG_LOGBOOKS);
- ITUtil.assertResponseLength2CodeOKContent(response, ITUtil.EMPTY_JSON);
+ ITUtilLogbooks.assertListLogbooks(2,
+ default_logbooks[1],
+ default_logbooks[0]);
// --------------------------------------------------------------------------------
// create
// --------------------------------------------------------------------------------
String name = URLEncoder.encode(logbookBuildings.getName(), StandardCharsets.UTF_8);
- response = ITUtil.runShellCommand(createCurlLogbookForAdmin(name, mapper.writeValueAsString(logbookBuildings)));
- ITUtil.assertResponseLength2CodeOK(response);
- assertEquals(logbookBuildings, mapper.readValue(response[1], Logbook.class));
+ ITUtilLogbooks.assertCreateLogbook("/" + name, logbookBuildings);
name = URLEncoder.encode(logbookCommunication.getName(), StandardCharsets.UTF_8);
- response = ITUtil.runShellCommand(createCurlLogbookForAdmin(name, mapper.writeValueAsString(logbookCommunication)));
- ITUtil.assertResponseLength2CodeOK(response);
- assertEquals(logbookCommunication, mapper.readValue(response[1], Logbook.class));
+ ITUtilLogbooks.assertCreateLogbook("/" + name, logbookCommunication);
name = URLEncoder.encode(logbookExperiments.getName(), StandardCharsets.UTF_8);
- response = ITUtil.runShellCommand(createCurlLogbookForAdmin(name, mapper.writeValueAsString(logbookExperiments)));
- ITUtil.assertResponseLength2CodeOK(response);
- assertEquals(logbookExperiments, mapper.readValue(response[1], Logbook.class));
+ ITUtilLogbooks.assertCreateLogbook("/" + name, logbookExperiments);
name = URLEncoder.encode(logbookFacilities.getName(), StandardCharsets.UTF_8);
- response = ITUtil.runShellCommand(createCurlLogbookForAdmin(name, mapper.writeValueAsString(logbookFacilities)));
- ITUtil.assertResponseLength2CodeOK(response);
- assertEquals(logbookFacilities, mapper.readValue(response[1], Logbook.class));
+ ITUtilLogbooks.assertCreateLogbook("/" + name, logbookFacilities);
name = URLEncoder.encode(logbookMaintenance.getName(), StandardCharsets.UTF_8);
- response = ITUtil.runShellCommand(createCurlLogbookForAdmin(name, mapper.writeValueAsString(logbookMaintenance)));
- ITUtil.assertResponseLength2CodeOK(response);
- assertTrue(logbookMaintenance.equals(mapper.readValue(response[1], Logbook.class)));
+ ITUtilLogbooks.assertCreateLogbook("/" + name, logbookMaintenance);
name = URLEncoder.encode(logbookOperations.getName(), ITUtil.UTF_8);
- response = ITUtil.runShellCommand(createCurlLogbookForAdmin(name, mapper.writeValueAsString(logbookOperations)));
- ITUtil.assertResponseLength2CodeOK(response);
- assertTrue(logbookOperations.equals(mapper.readValue(response[1], Logbook.class)));
+ ITUtilLogbooks.assertCreateLogbook("/" + name, logbookOperations);
name = URLEncoder.encode(logbookPower.getName(), ITUtil.UTF_8);
- response = ITUtil.runShellCommand(createCurlLogbookForAdmin(name, mapper.writeValueAsString(logbookPower)));
- ITUtil.assertResponseLength2CodeOK(response);
- assertTrue(logbookPower.equals(mapper.readValue(response[1], Logbook.class)));
+ ITUtilLogbooks.assertCreateLogbook("/" + name, logbookPower);
name = URLEncoder.encode(logbookServices.getName(), ITUtil.UTF_8);
- response = ITUtil.runShellCommand(createCurlLogbookForAdmin(name, mapper.writeValueAsString(logbookServices)));
- ITUtil.assertResponseLength2CodeOK(response);
- assertTrue(logbookServices.equals(mapper.readValue(response[1], Logbook.class)));
+ ITUtilLogbooks.assertCreateLogbook("/" + name, logbookServices);
name = URLEncoder.encode(logbookWater.getName(), ITUtil.UTF_8);
- response = ITUtil.runShellCommand(createCurlLogbookForAdmin(name, mapper.writeValueAsString(logbookWater)));
- ITUtil.assertResponseLength2CodeOK(response);
- assertTrue(logbookWater.equals(mapper.readValue(response[1], Logbook.class)));
+ ITUtilLogbooks.assertCreateLogbook("/" + name, logbookWater);
// refresh elastic indices
- response = ITUtil.refreshElasticIndices();
- ITUtil.assertResponseLength2CodeOK(response);
+ ITUtil.assertRefreshElasticIndices();
// --------------------------------------------------------------------------------
// well defined state
// --------------------------------------------------------------------------------
- response = ITUtil.doGetJson(OlogLogbooksIT.HTTP_IP_PORT_OLOG_LOGBOOKS);
- ITUtil.assertResponseLength2CodeOK(response);
- Logbook[] logbooks = mapper.readValue(response[1], Logbook[].class);
- assertNotNull(logbooks);
- assertEquals(9, logbooks.length);
- for (Logbook logbook : logbooks) {
- assertNotNull(logbook);
- }
+ ITUtilLogbooks.assertListLogbooks(10);
} catch (IOException e) {
e.printStackTrace();
fail();
- } catch (InterruptedException e) {
- e.printStackTrace();
- fail();
} catch (Exception e) {
e.printStackTrace();
fail();
@@ -508,82 +504,52 @@ private static void createLogbooks() {
* Create test fixture, tags.
*/
private static void createTags() {
- ObjectMapper mapper = new ObjectMapper();
-
try {
// --------------------------------------------------------------------------------
// clean start
// --------------------------------------------------------------------------------
- String[] response = ITUtil.doGetJson(OlogTagsIT.HTTP_IP_PORT_OLOG_TAGS);
- ITUtil.assertResponseLength2CodeOKContent(response, ITUtil.EMPTY_JSON);
+ ITUtilTags.assertListTags(1, default_tags[0]);
// --------------------------------------------------------------------------------
// create
// --------------------------------------------------------------------------------
String name = URLEncoder.encode(tagCryo.getName(), ITUtil.UTF_8);
- response = ITUtil.runShellCommand(createCurlTagForAdmin(name, mapper.writeValueAsString(tagCryo)));
- ITUtil.assertResponseLength2CodeOK(response);
- assertTrue(tagCryo.equals(mapper.readValue(response[1], Tag.class)));
+ ITUtilTags.assertCreateTag("/" + name, tagCryo);
name = URLEncoder.encode(tagPower.getName(), ITUtil.UTF_8);
- response = ITUtil.runShellCommand(createCurlTagForAdmin(name, mapper.writeValueAsString(tagPower)));
- ITUtil.assertResponseLength2CodeOK(response);
- assertTrue(tagPower.equals(mapper.readValue(response[1], Tag.class)));
+ ITUtilTags.assertCreateTag("/" + name, tagPower);
name = URLEncoder.encode(tagSafety.getName(), ITUtil.UTF_8);
- response = ITUtil.runShellCommand(createCurlTagForAdmin(name, mapper.writeValueAsString(tagSafety)));
- ITUtil.assertResponseLength2CodeOK(response);
- assertTrue(tagSafety.equals(mapper.readValue(response[1], Tag.class)));
+ ITUtilTags.assertCreateTag("/" + name, tagSafety);
name = URLEncoder.encode(tagSource.getName(), ITUtil.UTF_8);
- response = ITUtil.runShellCommand(createCurlTagForAdmin(name, mapper.writeValueAsString(tagSource)));
- ITUtil.assertResponseLength2CodeOK(response);
- assertTrue(tagSource.equals(mapper.readValue(response[1], Tag.class)));
+ ITUtilTags.assertCreateTag("/" + name, tagSource);
name = URLEncoder.encode(tagInitial.getName(), ITUtil.UTF_8);
- response = ITUtil.runShellCommand(createCurlTagForAdmin(name, mapper.writeValueAsString(tagInitial)));
- ITUtil.assertResponseLength2CodeOK(response);
- assertTrue(tagInitial.equals(mapper.readValue(response[1], Tag.class)));
+ ITUtilTags.assertCreateTag("/" + name, tagInitial);
name = URLEncoder.encode(tagRadio.getName(), ITUtil.UTF_8);
- response = ITUtil.runShellCommand(createCurlTagForAdmin(name, mapper.writeValueAsString(tagRadio)));
- ITUtil.assertResponseLength2CodeOK(response);
- assertTrue(tagRadio.equals(mapper.readValue(response[1], Tag.class)));
+ ITUtilTags.assertCreateTag("/" + name, tagRadio);
name = URLEncoder.encode(tagMagnet.getName(), ITUtil.UTF_8);
- response = ITUtil.runShellCommand(createCurlTagForAdmin(name, mapper.writeValueAsString(tagMagnet)));
- ITUtil.assertResponseLength2CodeOK(response);
- assertTrue(tagMagnet.equals(mapper.readValue(response[1], Tag.class)));
+ ITUtilTags.assertCreateTag("/" + name, tagMagnet);
name = URLEncoder.encode(tagSupra.getName(), ITUtil.UTF_8);
- response = ITUtil.runShellCommand(createCurlTagForAdmin(name, mapper.writeValueAsString(tagSupra)));
- ITUtil.assertResponseLength2CodeOK(response);
- assertEquals(tagSupra, mapper.readValue(response[1], Tag.class));
+ ITUtilTags.assertCreateTag("/" + name, tagSupra);
// refresh elastic indices
- response = ITUtil.refreshElasticIndices();
- ITUtil.assertResponseLength2CodeOK(response);
+ ITUtil.assertRefreshElasticIndices();
// --------------------------------------------------------------------------------
// well defined state
// --------------------------------------------------------------------------------
- response = ITUtil.doGetJson(OlogTagsIT.HTTP_IP_PORT_OLOG_TAGS);
- ITUtil.assertResponseLength2CodeOK(response);
- Tag[] tags = mapper.readValue(response[1], Tag[].class);
- assertNotNull(tags);
- assertEquals(8, tags.length);
- for (Tag tag : tags) {
- assertNotNull(tag);
- }
+ ITUtilTags.assertListTags(9);
} catch (IOException e) {
e.printStackTrace();
fail();
- } catch (InterruptedException e) {
- e.printStackTrace();
- fail();
} catch (Exception e) {
e.printStackTrace();
fail();
@@ -594,66 +560,41 @@ private static void createTags() {
* Create test fixture, properties.
*/
private static void createProperties() {
- ObjectMapper mapper = new ObjectMapper();
- String curl = null;
try {
// --------------------------------------------------------------------------------
// clean start
// --------------------------------------------------------------------------------
- String[] response = ITUtil.doGetJson(OlogPropertiesIT.HTTP_IP_PORT_OLOG_PROPERTIES);
- ITUtil.assertResponseLength2CodeOKContent(response, ITUtil.EMPTY_JSON);
+ ITUtilProperties.assertListProperties(1, default_properties[0]);
// --------------------------------------------------------------------------------
// create
// --------------------------------------------------------------------------------
String name = URLEncoder.encode(propertyShiftInfoCrewEmpty.getName(), StandardCharsets.UTF_8);
- response = ITUtil.runShellCommand(createCurlPropertyForAdmin(name, mapper.writeValueAsString(propertyShiftInfoCrewEmpty)));
- ITUtil.assertResponseLength2CodeOK(response);
- assertEquals(propertyShiftInfoCrewEmpty, mapper.readValue(response[1], Property.class));
+ ITUtilProperties.assertCreateProperty("/" + name, propertyShiftInfoCrewEmpty);
name = URLEncoder.encode(propertyShiftInfoACrew1.getName(), StandardCharsets.UTF_8);
- response = ITUtil.runShellCommand(createCurlPropertyForAdmin(name, mapper.writeValueAsString(propertyShiftInfoACrew1)));
- ITUtil.assertResponseLength2CodeOK(response);
- assertEquals(propertyShiftInfoACrew1, mapper.readValue(response[1], Property.class));
+ ITUtilProperties.assertCreateProperty("/" + name, propertyShiftInfoACrew1);
name = URLEncoder.encode(propertyShiftInfoBCrew2.getName(), StandardCharsets.UTF_8);
- response = ITUtil.runShellCommand(createCurlPropertyForAdmin(name, mapper.writeValueAsString(propertyShiftInfoBCrew2)));
- ITUtil.assertResponseLength2CodeOK(response);
- assertEquals(propertyShiftInfoBCrew2, mapper.readValue(response[1], Property.class));
+ ITUtilProperties.assertCreateProperty("/" + name, propertyShiftInfoBCrew2);
name = URLEncoder.encode(propertyShiftInfoCCrew3.getName(), StandardCharsets.UTF_8);
- response = ITUtil.runShellCommand(createCurlPropertyForAdmin(name, mapper.writeValueAsString(propertyShiftInfoCCrew3)));
- ITUtil.assertResponseLength2CodeOK(response);
- assertEquals(propertyShiftInfoCCrew3, mapper.readValue(response[1], Property.class));
+ ITUtilProperties.assertCreateProperty("/" + name, propertyShiftInfoCCrew3);
// refresh elastic indices
- response = ITUtil.refreshElasticIndices();
- ITUtil.assertResponseLength2CodeOK(response);
+ ITUtil.assertRefreshElasticIndices();
// --------------------------------------------------------------------------------
// well defined state
// --------------------------------------------------------------------------------
- response = ITUtil.doGetJson(OlogPropertiesIT.HTTP_IP_PORT_OLOG_PROPERTIES);
- ITUtil.assertResponseLength2CodeOK(response);
- Property[] properties = mapper.readValue(response[1], Property[].class);
- assertNotNull(properties);
- assertEquals(4, properties.length);
- for (Property property : properties) {
- assertNotNull(property);
- }
+ ITUtilProperties.assertListProperties(5);
} catch (IOException e) {
- System.out.println(curl);
- e.printStackTrace();
- fail();
- } catch (InterruptedException e) {
- System.out.println(curl);
e.printStackTrace();
fail();
} catch (Exception e) {
- System.out.println(curl);
e.printStackTrace();
fail();
}
@@ -664,283 +605,91 @@ private static void createProperties() {
*/
private static void createLogs() {
// logbooks, tags, properties to be created before log is created
-
- ObjectMapper mapper = new ObjectMapper();
-
try {
// --------------------------------------------------------------------------------
// clean start
// --------------------------------------------------------------------------------
- String[] response = ITUtil.doGetJson(OlogLogsIT.HTTP_IP_PORT_OLOG_LOGS);
- ITUtil.assertResponseLength2CodeOKContent(response, ITUtil.EMPTY_JSON);
+ ITUtilLogs.assertListLogs(0);
// --------------------------------------------------------------------------------
// create
// --------------------------------------------------------------------------------
- response = ITUtil.runShellCommand(createCurlLogForAdmin(mapper.writeValueAsString(logShiftA1001)));
- ITUtil.assertResponseLength2CodeOK(response);
- assertNotNull(mapper.readValue(response[1], Log.class));
-
- response = ITUtil.runShellCommand(createCurlLogForAdmin(mapper.writeValueAsString(logShiftA1011)));
- ITUtil.assertResponseLength2CodeOK(response);
- assertNotNull(mapper.readValue(response[1], Log.class));
-
- response = ITUtil.runShellCommand(createCurlLogForAdmin(mapper.writeValueAsString(logShiftA1021)));
- ITUtil.assertResponseLength2CodeOK(response);
- assertNotNull(mapper.readValue(response[1], Log.class));
-
- response = ITUtil.runShellCommand(createCurlLogForAdmin(mapper.writeValueAsString(logShiftA1031)));
- ITUtil.assertResponseLength2CodeOK(response);
- assertNotNull(mapper.readValue(response[1], Log.class));
-
- response = ITUtil.runShellCommand(createCurlLogForAdmin(mapper.writeValueAsString(logShiftA1041)));
- ITUtil.assertResponseLength2CodeOK(response);
- assertNotNull(mapper.readValue(response[1], Log.class));
-
- response = ITUtil.runShellCommand(createCurlLogForAdmin(mapper.writeValueAsString(logShiftA1051)));
- ITUtil.assertResponseLength2CodeOK(response);
- assertNotNull(mapper.readValue(response[1], Log.class));
-
- response = ITUtil.runShellCommand(createCurlLogForAdmin(mapper.writeValueAsString(logShiftA1061)));
- ITUtil.assertResponseLength2CodeOK(response);
- assertNotNull(mapper.readValue(response[1], Log.class));
-
- response = ITUtil.runShellCommand(createCurlLogForAdmin(mapper.writeValueAsString(logShiftA1071)));
- ITUtil.assertResponseLength2CodeOK(response);
- assertNotNull(mapper.readValue(response[1], Log.class));
-
- response = ITUtil.runShellCommand(createCurlLogForAdmin(mapper.writeValueAsString(logShiftA1081)));
- ITUtil.assertResponseLength2CodeOK(response);
- assertNotNull(mapper.readValue(response[1], Log.class));
-
- response = ITUtil.runShellCommand(createCurlLogForAdmin(mapper.writeValueAsString(logShiftA1091)));
- ITUtil.assertResponseLength2CodeOK(response);
- assertNotNull(mapper.readValue(response[1], Log.class));
-
- response = ITUtil.runShellCommand(createCurlLogForAdmin(mapper.writeValueAsString(logShiftA1101)));
- ITUtil.assertResponseLength2CodeOK(response);
- assertNotNull(mapper.readValue(response[1], Log.class));
-
- response = ITUtil.runShellCommand(createCurlLogForAdmin(mapper.writeValueAsString(logShiftA1111)));
- ITUtil.assertResponseLength2CodeOK(response);
- assertNotNull(mapper.readValue(response[1], Log.class));
-
- response = ITUtil.runShellCommand(createCurlLogForAdmin(mapper.writeValueAsString(logShiftA1121)));
- ITUtil.assertResponseLength2CodeOK(response);
- assertNotNull(mapper.readValue(response[1], Log.class));
-
- response = ITUtil.runShellCommand(createCurlLogForAdmin(mapper.writeValueAsString(logShiftA1131)));
- ITUtil.assertResponseLength2CodeOK(response);
- assertNotNull(mapper.readValue(response[1], Log.class));
-
- response = ITUtil.runShellCommand(createCurlLogForAdmin(mapper.writeValueAsString(logShiftA1141)));
- ITUtil.assertResponseLength2CodeOK(response);
- assertNotNull(mapper.readValue(response[1], Log.class));
-
- response = ITUtil.runShellCommand(createCurlLogForAdmin(mapper.writeValueAsString(logShiftA1151)));
- ITUtil.assertResponseLength2CodeOK(response);
- assertNotNull(mapper.readValue(response[1], Log.class));
-
- response = ITUtil.runShellCommand(createCurlLogForAdmin(mapper.writeValueAsString(logShiftA1161)));
- ITUtil.assertResponseLength2CodeOK(response);
- assertNotNull(mapper.readValue(response[1], Log.class));
-
- response = ITUtil.runShellCommand(createCurlLogForAdmin(mapper.writeValueAsString(logShiftA1171)));
- ITUtil.assertResponseLength2CodeOK(response);
- assertNotNull(mapper.readValue(response[1], Log.class));
-
- response = ITUtil.runShellCommand(createCurlLogForAdmin(mapper.writeValueAsString(logShiftA1181)));
- ITUtil.assertResponseLength2CodeOK(response);
- assertNotNull(mapper.readValue(response[1], Log.class));
-
- response = ITUtil.runShellCommand(createCurlLogForAdmin(mapper.writeValueAsString(logShiftA1191)));
- ITUtil.assertResponseLength2CodeOK(response);
- assertNotNull(mapper.readValue(response[1], Log.class));
-
- response = ITUtil.runShellCommand(createCurlLogForAdmin(mapper.writeValueAsString(logShiftB2001)));
- ITUtil.assertResponseLength2CodeOK(response);
- assertNotNull(mapper.readValue(response[1], Log.class));
-
- response = ITUtil.runShellCommand(createCurlLogForAdmin(mapper.writeValueAsString(logShiftB2011)));
- ITUtil.assertResponseLength2CodeOK(response);
- assertNotNull(mapper.readValue(response[1], Log.class));
-
- response = ITUtil.runShellCommand(createCurlLogForAdmin(mapper.writeValueAsString(logShiftB2021)));
- ITUtil.assertResponseLength2CodeOK(response);
- assertNotNull(mapper.readValue(response[1], Log.class));
-
- response = ITUtil.runShellCommand(createCurlLogForAdmin(mapper.writeValueAsString(logShiftB2031)));
- ITUtil.assertResponseLength2CodeOK(response);
- assertNotNull(mapper.readValue(response[1], Log.class));
-
- response = ITUtil.runShellCommand(createCurlLogForAdmin(mapper.writeValueAsString(logShiftB2041)));
- ITUtil.assertResponseLength2CodeOK(response);
- assertNotNull(mapper.readValue(response[1], Log.class));
-
- response = ITUtil.runShellCommand(createCurlLogForAdmin(mapper.writeValueAsString(logShiftB2051)));
- ITUtil.assertResponseLength2CodeOK(response);
- assertNotNull(mapper.readValue(response[1], Log.class));
-
- response = ITUtil.runShellCommand(createCurlLogForAdmin(mapper.writeValueAsString(logShiftB2061)));
- ITUtil.assertResponseLength2CodeOK(response);
- assertNotNull(mapper.readValue(response[1], Log.class));
-
- response = ITUtil.runShellCommand(createCurlLogForAdmin(mapper.writeValueAsString(logShiftB2071)));
- ITUtil.assertResponseLength2CodeOK(response);
- assertNotNull(mapper.readValue(response[1], Log.class));
-
- response = ITUtil.runShellCommand(createCurlLogForAdmin(mapper.writeValueAsString(logShiftB2081)));
- ITUtil.assertResponseLength2CodeOK(response);
- assertNotNull(mapper.readValue(response[1], Log.class));
-
- response = ITUtil.runShellCommand(createCurlLogForAdmin(mapper.writeValueAsString(logShiftB2091)));
- ITUtil.assertResponseLength2CodeOK(response);
- assertNotNull(mapper.readValue(response[1], Log.class));
-
- response = ITUtil.runShellCommand(createCurlLogForAdmin(mapper.writeValueAsString(logShiftB2101)));
- ITUtil.assertResponseLength2CodeOK(response);
- assertNotNull(mapper.readValue(response[1], Log.class));
-
- response = ITUtil.runShellCommand(createCurlLogForAdmin(mapper.writeValueAsString(logShiftB2111)));
- ITUtil.assertResponseLength2CodeOK(response);
- assertNotNull(mapper.readValue(response[1], Log.class));
-
- response = ITUtil.runShellCommand(createCurlLogForAdmin(mapper.writeValueAsString(logShiftB2121)));
- ITUtil.assertResponseLength2CodeOK(response);
- assertNotNull(mapper.readValue(response[1], Log.class));
-
- response = ITUtil.runShellCommand(createCurlLogForAdmin(mapper.writeValueAsString(logShiftB2131)));
- ITUtil.assertResponseLength2CodeOK(response);
- assertNotNull(mapper.readValue(response[1], Log.class));
-
- response = ITUtil.runShellCommand(createCurlLogForAdmin(mapper.writeValueAsString(logShiftB2141)));
- ITUtil.assertResponseLength2CodeOK(response);
- assertNotNull(mapper.readValue(response[1], Log.class));
-
- response = ITUtil.runShellCommand(createCurlLogForAdmin(mapper.writeValueAsString(logShiftB2151)));
- ITUtil.assertResponseLength2CodeOK(response);
- assertNotNull(mapper.readValue(response[1], Log.class));
-
- response = ITUtil.runShellCommand(createCurlLogForAdmin(mapper.writeValueAsString(logShiftB2161)));
- ITUtil.assertResponseLength2CodeOK(response);
- assertNotNull(mapper.readValue(response[1], Log.class));
-
- response = ITUtil.runShellCommand(createCurlLogForAdmin(mapper.writeValueAsString(logShiftB2171)));
- ITUtil.assertResponseLength2CodeOK(response);
- assertNotNull(mapper.readValue(response[1], Log.class));
-
- response = ITUtil.runShellCommand(createCurlLogForAdmin(mapper.writeValueAsString(logShiftB2181)));
- ITUtil.assertResponseLength2CodeOK(response);
- assertNotNull(mapper.readValue(response[1], Log.class));
-
- response = ITUtil.runShellCommand(createCurlLogForAdmin(mapper.writeValueAsString(logShiftB2191)));
- ITUtil.assertResponseLength2CodeOK(response);
- assertNotNull(mapper.readValue(response[1], Log.class));
-
- response = ITUtil.runShellCommand(createCurlLogForAdmin(mapper.writeValueAsString(logShiftC3001)));
- ITUtil.assertResponseLength2CodeOK(response);
- assertNotNull(mapper.readValue(response[1], Log.class));
-
- response = ITUtil.runShellCommand(createCurlLogForAdmin(mapper.writeValueAsString(logShiftC3011)));
- ITUtil.assertResponseLength2CodeOK(response);
- assertNotNull(mapper.readValue(response[1], Log.class));
-
- response = ITUtil.runShellCommand(createCurlLogForAdmin(mapper.writeValueAsString(logShiftC3021)));
- ITUtil.assertResponseLength2CodeOK(response);
- assertNotNull(mapper.readValue(response[1], Log.class));
-
- response = ITUtil.runShellCommand(createCurlLogForAdmin(mapper.writeValueAsString(logShiftC3031)));
- ITUtil.assertResponseLength2CodeOK(response);
- assertNotNull(mapper.readValue(response[1], Log.class));
-
- response = ITUtil.runShellCommand(createCurlLogForAdmin(mapper.writeValueAsString(logShiftC3041)));
- ITUtil.assertResponseLength2CodeOK(response);
- assertNotNull(mapper.readValue(response[1], Log.class));
-
- response = ITUtil.runShellCommand(createCurlLogForAdmin(mapper.writeValueAsString(logShiftC3051)));
- ITUtil.assertResponseLength2CodeOK(response);
- assertNotNull(mapper.readValue(response[1], Log.class));
-
- response = ITUtil.runShellCommand(createCurlLogForAdmin(mapper.writeValueAsString(logShiftC3061)));
- ITUtil.assertResponseLength2CodeOK(response);
- assertNotNull(mapper.readValue(response[1], Log.class));
-
- response = ITUtil.runShellCommand(createCurlLogForAdmin(mapper.writeValueAsString(logShiftC3071)));
- ITUtil.assertResponseLength2CodeOK(response);
- assertNotNull(mapper.readValue(response[1], Log.class));
-
- response = ITUtil.runShellCommand(createCurlLogForAdmin(mapper.writeValueAsString(logShiftC3081)));
- ITUtil.assertResponseLength2CodeOK(response);
- assertNotNull(mapper.readValue(response[1], Log.class));
-
- response = ITUtil.runShellCommand(createCurlLogForAdmin(mapper.writeValueAsString(logShiftC3091)));
- ITUtil.assertResponseLength2CodeOK(response);
- assertNotNull(mapper.readValue(response[1], Log.class));
-
- response = ITUtil.runShellCommand(createCurlLogForAdmin(mapper.writeValueAsString(logShiftC3101)));
- ITUtil.assertResponseLength2CodeOK(response);
- assertNotNull(mapper.readValue(response[1], Log.class));
-
- response = ITUtil.runShellCommand(createCurlLogForAdmin(mapper.writeValueAsString(logShiftC3111)));
- ITUtil.assertResponseLength2CodeOK(response);
- assertNotNull(mapper.readValue(response[1], Log.class));
-
- response = ITUtil.runShellCommand(createCurlLogForAdmin(mapper.writeValueAsString(logShiftC3121)));
- ITUtil.assertResponseLength2CodeOK(response);
- assertNotNull(mapper.readValue(response[1], Log.class));
-
- response = ITUtil.runShellCommand(createCurlLogForAdmin(mapper.writeValueAsString(logShiftC3131)));
- ITUtil.assertResponseLength2CodeOK(response);
- assertNotNull(mapper.readValue(response[1], Log.class));
-
- response = ITUtil.runShellCommand(createCurlLogForAdmin(mapper.writeValueAsString(logShiftC3141)));
- ITUtil.assertResponseLength2CodeOK(response);
- assertNotNull(mapper.readValue(response[1], Log.class));
-
- response = ITUtil.runShellCommand(createCurlLogForAdmin(mapper.writeValueAsString(logShiftC3151)));
- ITUtil.assertResponseLength2CodeOK(response);
- assertNotNull(mapper.readValue(response[1], Log.class));
-
- response = ITUtil.runShellCommand(createCurlLogForAdmin(mapper.writeValueAsString(logShiftC3161)));
- ITUtil.assertResponseLength2CodeOK(response);
- assertNotNull(mapper.readValue(response[1], Log.class));
-
- response = ITUtil.runShellCommand(createCurlLogForAdmin(mapper.writeValueAsString(logShiftC3171)));
- ITUtil.assertResponseLength2CodeOK(response);
- assertNotNull(mapper.readValue(response[1], Log.class));
-
- response = ITUtil.runShellCommand(createCurlLogForAdmin(mapper.writeValueAsString(logShiftC3181)));
- ITUtil.assertResponseLength2CodeOK(response);
- assertNotNull(mapper.readValue(response[1], Log.class));
-
- response = ITUtil.runShellCommand(createCurlLogForAdmin(mapper.writeValueAsString(logShiftC3191)));
- ITUtil.assertResponseLength2CodeOK(response);
- assertNotNull(mapper.readValue(response[1], Log.class));
+ ITUtilLogs.assertCreateLog("", logShiftA1001);
+ ITUtilLogs.assertCreateLog("", logShiftA1011);
+ ITUtilLogs.assertCreateLog("", logShiftA1021);
+ ITUtilLogs.assertCreateLog("", logShiftA1031);
+ ITUtilLogs.assertCreateLog("", logShiftA1041);
+ ITUtilLogs.assertCreateLog("", logShiftA1051);
+ ITUtilLogs.assertCreateLog("", logShiftA1061);
+ ITUtilLogs.assertCreateLog("", logShiftA1071);
+ ITUtilLogs.assertCreateLog("", logShiftA1081);
+ ITUtilLogs.assertCreateLog("", logShiftA1091);
+ ITUtilLogs.assertCreateLog("", logShiftA1101);
+ ITUtilLogs.assertCreateLog("", logShiftA1111);
+ ITUtilLogs.assertCreateLog("", logShiftA1121);
+ ITUtilLogs.assertCreateLog("", logShiftA1131);
+ ITUtilLogs.assertCreateLog("", logShiftA1141);
+ ITUtilLogs.assertCreateLog("", logShiftA1151);
+ ITUtilLogs.assertCreateLog("", logShiftA1161);
+ ITUtilLogs.assertCreateLog("", logShiftA1171);
+ ITUtilLogs.assertCreateLog("", logShiftA1181);
+ ITUtilLogs.assertCreateLog("", logShiftA1191);
+
+ ITUtilLogs.assertCreateLog("", logShiftB2001);
+ ITUtilLogs.assertCreateLog("", logShiftB2011);
+ ITUtilLogs.assertCreateLog("", logShiftB2021);
+ ITUtilLogs.assertCreateLog("", logShiftB2031);
+ ITUtilLogs.assertCreateLog("", logShiftB2041);
+ ITUtilLogs.assertCreateLog("", logShiftB2051);
+ ITUtilLogs.assertCreateLog("", logShiftB2061);
+ ITUtilLogs.assertCreateLog("", logShiftB2071);
+ ITUtilLogs.assertCreateLog("", logShiftB2081);
+ ITUtilLogs.assertCreateLog("", logShiftB2091);
+ ITUtilLogs.assertCreateLog("", logShiftB2101);
+ ITUtilLogs.assertCreateLog("", logShiftB2111);
+ ITUtilLogs.assertCreateLog("", logShiftB2121);
+ ITUtilLogs.assertCreateLog("", logShiftB2131);
+ ITUtilLogs.assertCreateLog("", logShiftB2141);
+ ITUtilLogs.assertCreateLog("", logShiftB2151);
+ ITUtilLogs.assertCreateLog("", logShiftB2161);
+ ITUtilLogs.assertCreateLog("", logShiftB2171);
+ ITUtilLogs.assertCreateLog("", logShiftB2181);
+ ITUtilLogs.assertCreateLog("", logShiftB2191);
+
+ ITUtilLogs.assertCreateLog("", logShiftC3001);
+ ITUtilLogs.assertCreateLog("", logShiftC3011);
+ ITUtilLogs.assertCreateLog("", logShiftC3021);
+ ITUtilLogs.assertCreateLog("", logShiftC3031);
+ ITUtilLogs.assertCreateLog("", logShiftC3041);
+ ITUtilLogs.assertCreateLog("", logShiftC3051);
+ ITUtilLogs.assertCreateLog("", logShiftC3061);
+ ITUtilLogs.assertCreateLog("", logShiftC3071);
+ ITUtilLogs.assertCreateLog("", logShiftC3081);
+ ITUtilLogs.assertCreateLog("", logShiftC3091);
+ ITUtilLogs.assertCreateLog("", logShiftC3101);
+ ITUtilLogs.assertCreateLog("", logShiftC3111);
+ ITUtilLogs.assertCreateLog("", logShiftC3121);
+ ITUtilLogs.assertCreateLog("", logShiftC3131);
+ ITUtilLogs.assertCreateLog("", logShiftC3141);
+ ITUtilLogs.assertCreateLog("", logShiftC3151);
+ ITUtilLogs.assertCreateLog("", logShiftC3161);
+ ITUtilLogs.assertCreateLog("", logShiftC3171);
+ ITUtilLogs.assertCreateLog("", logShiftC3181);
+ ITUtilLogs.assertCreateLog("", logShiftC3191);
// refresh elastic indices
- response = ITUtil.refreshElasticIndices();
- ITUtil.assertResponseLength2CodeOK(response);
+ ITUtil.assertRefreshElasticIndices();
// --------------------------------------------------------------------------------
// well defined state
// --------------------------------------------------------------------------------
- response = ITUtil.doGetJson(OlogLogsIT.HTTP_IP_PORT_OLOG_LOGS);
- ITUtil.assertResponseLength2CodeOK(response);
- Log[] logs = mapper.readValue(response[1], Log[].class);
- assertNotNull(logs);
- assertEquals(60, logs.length);
- for (Log log : logs) {
- assertNotNull(log);
- }
+ ITUtilLogs.assertListLogs(60);
} catch (IOException e) {
e.printStackTrace();
fail();
- } catch (InterruptedException e) {
- e.printStackTrace();
- fail();
} catch (Exception e) {
e.printStackTrace();
fail();
@@ -1098,47 +847,4 @@ private static Log createLog(
return log;
}
- /**
- * Utility method to return curl to create logbook for admin user.
- *
- * @param logbookName logbook name
- * @param logbookJson logbook json
- * @return curl to create logbook
- */
- private static String createCurlLogbookForAdmin(String logbookName, String logbookJson) {
- return "curl -H " + ITUtil.HEADER_JSON + " -XPUT -i " + OlogLogbooksIT.HTTP_AUTH_ADMIN_IP_PORT_OLOG_LOGBOOKS + "/" + logbookName + " -d '" + logbookJson + "'";
- }
-
- /**
- * Utility method to return curl to create tag for admin user.
- *
- * @param tagName tag name
- * @param tagJson tag json
- * @return curl to create tag
- */
- private static String createCurlTagForAdmin(String tagName, String tagJson) {
- return "curl -H " + ITUtil.HEADER_JSON + " -XPUT -i " + OlogTagsIT.HTTP_AUTH_ADMIN_IP_PORT_OLOG_TAGS + "/" + tagName + " -d '" + tagJson + "'";
- }
-
- /**
- * Utility method to return curl to create property for admin user.
- *
- * @param propertyName property name
- * @param propertyJson propery json
- * @return curl to create property
- */
- private static String createCurlPropertyForAdmin(String propertyName, String propertyJson) {
- return "curl -H " + ITUtil.HEADER_JSON + " -XPUT -i " + OlogPropertiesIT.HTTP_AUTH_ADMIN_IP_PORT_OLOG_PROPERTIES + "/" + propertyName + " -d '" + propertyJson + "'";
- }
-
- /**
- * Utility method to return curl to create log for admin user.
- *
- * @param logJson log json
- * @return curl to create log
- */
- private static String createCurlLogForAdmin(String logJson) {
- return "curl -H " + ITUtil.HEADER_JSON + " -XPUT -i " + OlogLogsIT.HTTP_AUTH_ADMIN_IP_PORT_OLOG_LOGS + " -d '" + logJson + "'";
- }
-
}
diff --git a/src/test/java/org/phoebus/olog/docker/ITUtil.java b/src/test/java/org/phoebus/olog/docker/ITUtil.java
index 8261afd..91f5bc4 100644
--- a/src/test/java/org/phoebus/olog/docker/ITUtil.java
+++ b/src/test/java/org/phoebus/olog/docker/ITUtil.java
@@ -1,29 +1,51 @@
/*
* Copyright (C) 2021 European Spallation Source ERIC.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
package org.phoebus.olog.docker;
+import org.junit.jupiter.api.AfterAll;
import org.phoebus.olog.entity.Log;
import org.phoebus.olog.entity.Logbook;
import org.phoebus.olog.entity.Property;
import org.phoebus.olog.entity.Tag;
+import org.testcontainers.containers.ComposeContainer;
+import org.testcontainers.containers.ContainerState;
+import org.testcontainers.containers.wait.strategy.Wait;
+import org.testcontainers.shaded.org.apache.commons.lang3.StringUtils;
+
+import com.github.dockerjava.api.DockerClient;
import java.io.BufferedReader;
+import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
+import java.util.Optional;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
-import static org.junit.jupiter.api.Assertions.assertTrue;
/**
- * Utility class to help (Docker) integration tests for Olog and Elasticsearch.
+ * Utility class to help (Docker) integration tests for Olog and Elasticsearch with focus on support common behavior for tests.
*
* @author Lars Johansson
*/
@@ -42,15 +64,48 @@ public class ITUtil {
static final String IP_PORT_OLOG = "127.0.0.1:8080/Olog";
static final String IP_PORT_ELASTICSEARCH = "127.0.0.1:9200";
+ static final String LOGBOOKS = "/logbooks";
+ static final String LOGS = "/logs";
+ static final String PROPERTIES = "/properties";
+ static final String TAGS = "/tags";
+
static final String HTTP_IP_PORT_OLOG = HTTP + IP_PORT_OLOG;
static final String HTTP_IP_PORT_ELASTICSEARCH = HTTP + IP_PORT_ELASTICSEARCH;
+ static final String HTTP_IP_PORT_OLOG_LOGBOOKS = ITUtil.HTTP + ITUtil.IP_PORT_OLOG + LOGBOOKS;
+ static final String HTTP_AUTH_USER_IP_PORT_OLOG_LOGBOOKS = ITUtil.HTTP + ITUtil.AUTH_USER + "@" + ITUtil.IP_PORT_OLOG + LOGBOOKS;
+ static final String HTTP_AUTH_ADMIN_IP_PORT_OLOG_LOGBOOKS = ITUtil.HTTP + ITUtil.AUTH_ADMIN + "@" + ITUtil.IP_PORT_OLOG + LOGBOOKS;
+
+ static final String HTTP_IP_PORT_OLOG_LOGS = ITUtil.HTTP + ITUtil.IP_PORT_OLOG + LOGS;
+ static final String HTTP_AUTH_USER_IP_PORT_OLOG_LOGS = ITUtil.HTTP + ITUtil.AUTH_USER + "@" + ITUtil.IP_PORT_OLOG + LOGS;
+ static final String HTTP_AUTH_ADMIN_IP_PORT_OLOG_LOGS = ITUtil.HTTP + ITUtil.AUTH_ADMIN + "@" + ITUtil.IP_PORT_OLOG + LOGS;
+
+ static final String HTTP_IP_PORT_OLOG_PROPERTIES = ITUtil.HTTP + ITUtil.IP_PORT_OLOG + PROPERTIES;
+ static final String HTTP_AUTH_USER_IP_PORT_OLOG_PROPERTIES = ITUtil.HTTP + ITUtil.AUTH_USER + "@" + ITUtil.IP_PORT_OLOG + PROPERTIES;
+ static final String HTTP_AUTH_ADMIN_IP_PORT_OLOG_PROPERTIES = ITUtil.HTTP + ITUtil.AUTH_ADMIN + "@" + ITUtil.IP_PORT_OLOG + PROPERTIES;
+
+ static final String HTTP_IP_PORT_OLOG_TAGS = ITUtil.HTTP + ITUtil.IP_PORT_OLOG + TAGS;
+ static final String HTTP_AUTH_USER_IP_PORT_OLOG_TAGS = ITUtil.HTTP + ITUtil.AUTH_USER + "@" + ITUtil.IP_PORT_OLOG + TAGS;
+ static final String HTTP_AUTH_ADMIN_IP_PORT_OLOG_TAGS = ITUtil.HTTP + ITUtil.AUTH_ADMIN + "@" + ITUtil.IP_PORT_OLOG + TAGS;
+
private static final String BRACKET_BEGIN = "[";
private static final String BRACKET_END = "]";
private static final String CURLY_BRACE_BEGIN = "{";
private static final String CURLY_BRACE_END = "}";
private static final String HTTP_REPLY = "HTTP";
+ // integration test - docker
+
+ public static final String INTEGRATIONTEST_DOCKER_COMPOSE = "docker-compose-integrationtest.yml";
+ public static final String INTEGRATIONTEST_LOG_MESSAGE = ".*Started Application.*";
+
+ // code coverage
+
+ public static final String JACOCO_EXEC_PATH = "/olog-target/jacoco.exec";
+ public static final String JACOCO_TARGET_PREFIX = "target/jacoco_";
+ public static final String JACOCO_TARGET_SUFFIX = ".exec";
+ public static final String JACOCO_SKIPITCOVERAGE = "skipITCoverage";
+
/**
* This class is not to be instantiated.
*/
@@ -58,6 +113,49 @@ private ITUtil() {
throw new IllegalStateException("Utility class");
}
+ /**
+ * Provide a default compose setup for testing.
+ * For Docker Compose V2.
+ *
+ * Intended usage is as field annotated with @Container from class annotated with @Testcontainers.
+ *
+ * @return compose container
+ */
+ public static ComposeContainer defaultComposeContainers() {
+ return new ComposeContainer(new File(ITUtil.INTEGRATIONTEST_DOCKER_COMPOSE))
+ .withEnv(ITUtil.JACOCO_SKIPITCOVERAGE, System.getProperty(ITUtil.JACOCO_SKIPITCOVERAGE))
+ .withLocalCompose(true)
+ .waitingFor(ITUtil.OLOG, Wait.forLogMessage(ITUtil.INTEGRATIONTEST_LOG_MESSAGE, 1));
+ }
+
+ /**
+ * Extract coverage report from compose container to file system.
+ *
+ * @param environment compose container
+ * @param destinationPath destination path, i.e. where in file system to put coverage report
+ * that has been extracted from container
+ */
+ public static void extractJacocoReport(ComposeContainer environment, String destinationPath) {
+ // extract jacoco report from container file system
+ // stop jvm to make data available
+
+ if (!Boolean.FALSE.toString().equals(System.getProperty(ITUtil.JACOCO_SKIPITCOVERAGE))) {
+ return;
+ }
+
+ Optional container = environment.getContainerByServiceName(ITUtil.OLOG);
+ if (container.isPresent()) {
+ ContainerState cs = container.get();
+ DockerClient dc = cs.getDockerClient();
+ dc.stopContainerCmd(cs.getContainerId()).exec();
+ try {
+ cs.copyFileFromContainer(ITUtil.JACOCO_EXEC_PATH, destinationPath);
+ } catch (Exception e) {
+ // proceed if file cannot be copied
+ }
+ }
+ }
+
/**
* Refresh Elastic indices and return response code and string.
*
@@ -68,6 +166,16 @@ static String[] refreshElasticIndices() throws IOException {
return doGetJson(HTTP_IP_PORT_ELASTICSEARCH + "/_refresh");
}
+ /**
+ * Refresh Elastic indices and assert response is of length 2 and has response code HttpURLConnection.HTTP_OK.
+ *
+ * @throws IOException
+ */
+ static void assertRefreshElasticIndices() throws IOException {
+ String[] response = doGetJson(HTTP_IP_PORT_ELASTICSEARCH + "/_refresh");
+ ITUtil.assertResponseLength2CodeOK(response);
+ }
+
/**
* Do GET request with given string as URL and return response code.
*
@@ -162,6 +270,111 @@ static String[] runShellCommand(String command) throws IOException, InterruptedE
return new String[] {responseCode, responseContent};
}
+ // ----------------------------------------------------------------------------------------------------
+
+ // enum for http methods
+ static enum MethodChoice {POST, GET, PUT, DELETE};
+
+ // enum for different authorizations
+ static enum AuthorizationChoice {NONE, USER, ADMIN};
+
+ // enum for different endpoints
+ static enum EndpointChoice {LOGBOOKS, LOGS, PROPERTIES, TAGS};
+
+ /**
+ * Prepare curl command for test to run for contacting server.
+ *
+ * @param methodChoice method choice
+ * @param authorizationChoice authorization choice
+ * @param endpointChoice endpoint choice
+ * @param path particular path
+ * @param json json data
+ * @return curl command to run
+ */
+ static String curlMethodAuthEndpointPathJson(MethodChoice methodChoice, AuthorizationChoice authorizationChoice, EndpointChoice endpointChoice, String path, String json) {
+ String pathstr = !StringUtils.isEmpty(path)
+ ? path
+ : "";
+
+ String data = !StringUtils.isEmpty(json)
+ ? " -d '" + json + "'"
+ : "";
+
+ return "curl"
+ + " -H " + ITUtil.HEADER_JSON
+ + " -X" + ITUtil.getMethodString(methodChoice)
+ + " -i "
+ + ITUtil.HTTP
+ + ITUtil.getAuthorizationString(authorizationChoice)
+ + ITUtil.IP_PORT_OLOG
+ + ITUtil.getEndpointString(endpointChoice)
+ + pathstr
+ + data;
+ }
+
+ /**
+ * Utility method to return string for http method. To be used when constructing url to send query to server.
+ *
+ * @param methodChoice method choice, i.e. POST, GET, PUT, DELETE, PATCH
+ * @return string for http method
+ */
+ private static String getMethodString(MethodChoice methodChoice) {
+ switch (methodChoice) {
+ case POST:
+ return "POST";
+ case GET:
+ return "GET";
+ case PUT:
+ return "PUT";
+ case DELETE:
+ return "DELETE";
+ default:
+ return "GET";
+ }
+ }
+
+ /**
+ * Utility method to return string for authorization. To be used when constructing url to send query to server.
+ *
+ * @param authorizationChoice authorization choice
+ * @return string for authorization
+ */
+ private static String getAuthorizationString(AuthorizationChoice authorizationChoice) {
+ switch (authorizationChoice) {
+ case ADMIN:
+ return ITUtil.AUTH_ADMIN + "@";
+ case USER:
+ return ITUtil.AUTH_USER + "@";
+ case NONE:
+ return StringUtils.EMPTY;
+ default:
+ return StringUtils.EMPTY;
+ }
+ }
+
+ /**
+ * Utility method to return string for endpoint. To be used when constructing url to send query to server.
+ *
+ * @param endpointChoice endpoint choice
+ * @return string for endpoint
+ */
+ private static String getEndpointString(EndpointChoice endpointChoice) {
+ switch (endpointChoice) {
+ case LOGBOOKS:
+ return ITUtil.LOGBOOKS;
+ case LOGS:
+ return ITUtil.LOGS;
+ case PROPERTIES:
+ return ITUtil.PROPERTIES;
+ case TAGS:
+ return ITUtil.TAGS;
+ default:
+ return StringUtils.EMPTY;
+ }
+ }
+
+ // ----------------------------------------------------------------------------------------------------
+
/**
* Assert that response object is as expected, an array with 2 elements
* of which first contains response code OK (200).
@@ -179,14 +392,14 @@ static void assertResponseLength2CodeOK(String[] response) {
* of which first element contains given response code.
*
* @param response string array with response of http request, response code and content
- * @param responseCode expected response code
+ * @param expectedResponseCode expected response code
*
* @see HttpURLConnection for available response codes
*/
- static void assertResponseLength2Code(String[] response, int responseCode) {
+ static void assertResponseLength2Code(String[] response, int expectedResponseCode) {
assertNotNull(response);
assertEquals(2, response.length);
- assertEquals(responseCode, Integer.parseInt(response[0]));
+ assertEquals(expectedResponseCode, Integer.parseInt(response[0]));
}
/**
@@ -194,12 +407,12 @@ static void assertResponseLength2Code(String[] response, int responseCode) {
* of which first element contains response code OK (200) and second element contains given response content.
*
* @param response string array with response of http request, response code and content
- * @param responseContent expected response content
+ * @param expectedResponseContent expected response content
*
* @see HttpURLConnection#HTTP_OK
*/
- static void assertResponseLength2CodeOKContent(String[] response, String responseContent) {
- assertResponseLength2CodeContent(response, HttpURLConnection.HTTP_OK, responseContent);
+ static void assertResponseLength2CodeOKContent(String[] response, String expectedResponseContent) {
+ assertResponseLength2CodeContent(response, HttpURLConnection.HTTP_OK, expectedResponseContent);
}
/**
@@ -207,21 +420,21 @@ static void assertResponseLength2CodeOKContent(String[] response, String respons
* of which first element contains given response code and second element contains given response content.
*
* @param response string array with response of http request, response code and content
- * @param responseCode expected response code
- * @param responseContent expected response content
+ * @param expectedResponseCode expected response code
+ * @param expectedResponseContent expected response content
*
* @see HttpURLConnection for available response codes
*/
- static void assertResponseLength2CodeContent(String[] response, int responseCode, String responseContent) {
- assertResponseLength2Code(response, responseCode);
- assertEquals(responseContent, response[1]);
+ static void assertResponseLength2CodeContent(String[] response, int expectedResponseCode, String expectedResponseContent) {
+ assertResponseLength2Code(response, expectedResponseCode);
+ assertEquals(expectedResponseContent, response[1]);
}
/**
* Assert that arrays are equal with same length and same content in each array position.
*
- * @param actual actual array of XmlTag objects
- * @param expected expected arbitrary number of XmlTag objects
+ * @param actual actual array of Tag objects
+ * @param expected expected arbitrary number of Tag objects
*/
static void assertEqualsTags(Tag[] actual, Tag... expected) {
if (expected != null) {
@@ -238,8 +451,8 @@ static void assertEqualsTags(Tag[] actual, Tag... expected) {
/**
* Assert that arrays are equal with same length and same content in each array position.
*
- * @param actual actual array of XmlTag objects
- * @param expected expected arbitrary number of XmlTag objects
+ * @param actual actual array of Logbook objects
+ * @param expected expected arbitrary number of Logbook objects
*/
static void assertEqualsLogbooks(Logbook[] actual, Logbook... expected) {
if (expected != null) {
@@ -256,8 +469,8 @@ static void assertEqualsLogbooks(Logbook[] actual, Logbook... expected) {
/**
* Assert that arrays are equal with same length and same content in each array position.
*
- * @param actual actual array of XmlTag objects
- * @param expected expected arbitrary number of XmlTag objects
+ * @param actual actual array of Property objects
+ * @param expected expected arbitrary number of Property objects
*/
static void assertEqualsProperties(Property[] actual, Property... expected) {
if (expected != null) {
@@ -274,8 +487,8 @@ static void assertEqualsProperties(Property[] actual, Property... expected) {
/**
* Assert that arrays are equal with same length and same content in each array position.
*
- * @param actual actual array of XmlTag objects
- * @param expected expected arbitrary number of XmlTag objects
+ * @param actual actual array of Log objects
+ * @param expected expected arbitrary number of Log objects
*/
static void assertEqualsLogs(Log[] actual, Log... expected) {
if (expected != null) {
diff --git a/src/test/java/org/phoebus/olog/docker/ITUtilLogbooks.java b/src/test/java/org/phoebus/olog/docker/ITUtilLogbooks.java
new file mode 100644
index 0000000..c9d2d26
--- /dev/null
+++ b/src/test/java/org/phoebus/olog/docker/ITUtilLogbooks.java
@@ -0,0 +1,325 @@
+/*
+ * Copyright (C) 2023 European Spallation Source ERIC.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+package org.phoebus.olog.docker;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
+
+import java.io.IOException;
+import java.net.HttpURLConnection;
+
+import org.phoebus.olog.docker.ITUtil.AuthorizationChoice;
+import org.phoebus.olog.docker.ITUtil.EndpointChoice;
+import org.phoebus.olog.docker.ITUtil.MethodChoice;
+import org.phoebus.olog.entity.Logbook;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+/**
+ * Utility class to help (Docker) integration tests for Olog and Elasticsearch with focus on support test of behavior for logbook endpoints.
+ *
+ * @author Lars Johansson
+ *
+ * @see org.phoebus.olog.docker.ITUtil
+ */
+public class ITUtilLogbooks {
+
+ static final ObjectMapper mapper = new ObjectMapper();
+
+ static final Logbook[] LOGBOOKS_NULL = null;
+ static final Logbook LOGBOOK_NULL = null;
+
+ /**
+ * This class is not to be instantiated.
+ */
+ private ITUtilLogbooks() {
+ throw new IllegalStateException("Utility class");
+ }
+
+ // ----------------------------------------------------------------------------------------------------
+
+ /**
+ * Return string for logbook.
+ *
+ * @param value logbook
+ * @return string for logbook
+ */
+ static String object2Json(Logbook value) {
+ try {
+ return mapper.writeValueAsString(value);
+ } catch (JsonProcessingException e) {
+ fail();
+ }
+ return null;
+ }
+ /**
+ * Return string for logbook array.
+ *
+ * @param value logbook array
+ * @return string for logbook array
+ */
+ static String object2Json(Logbook[] value) {
+ try {
+ return mapper.writeValueAsString(value);
+ } catch (JsonProcessingException e) {
+ fail();
+ }
+ return null;
+ }
+
+ // ----------------------------------------------------------------------------------------------------
+
+ /**
+ * @see ITUtilLogbooks#assertRetrieveLogbook(String, int, Logbook)
+ */
+ public static Logbook assertRetrieveLogbook(String path, int expectedResponseCode) {
+ return assertRetrieveLogbook(path, expectedResponseCode, LOGBOOK_NULL);
+ }
+ /**
+ * @see ITUtilLogbooks#assertRetrieveLogbook(String, int, Logbook)
+ */
+ public static Logbook assertRetrieveLogbook(String path, Logbook expected) {
+ return assertRetrieveLogbook(path, HttpURLConnection.HTTP_OK, expected);
+ }
+ /**
+ * Utility method to return the logbook with the given name.
+ *
+ * @param path path
+ * @param expectedResponseCode expected response code
+ * @param expected expected response logbook
+ */
+ public static Logbook assertRetrieveLogbook(String path, int expectedResponseCode, Logbook expected) {
+ try {
+ String[] response = null;
+ Logbook actual = null;
+
+ response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_OLOG_LOGBOOKS + path);
+ ITUtil.assertResponseLength2Code(response, expectedResponseCode);
+ if (HttpURLConnection.HTTP_OK == expectedResponseCode) {
+ actual = mapper.readValue(response[1], Logbook.class);
+ }
+
+ if (expected != null) {
+ assertEquals(expected, actual);
+ }
+
+ return actual;
+ } catch (IOException e) {
+ fail();
+ } catch (Exception e) {
+ fail();
+ }
+ return null;
+ }
+
+ // ----------------------------------------------------------------------------------------------------
+
+ /**
+ * @see ITUtilLogbooks#assertListLogbooks(int, int, int, Logbook...)
+ */
+ public static Logbook[] assertListLogbooks(int expectedEqual, Logbook... expected) {
+ return assertListLogbooks(HttpURLConnection.HTTP_OK, expectedEqual, expectedEqual, expected);
+ }
+ /**
+ * Utility method to return the list of all logbooks in the directory.
+ *
+ * @param expectedResponseCode expected response code
+ * @param expectedGreaterThanOrEqual (if non-negative number) greater than or equal to this number of items
+ * @param expectedLessThanOrEqual (if non-negative number) less than or equal to this number of items
+ * @param expected expected response logbooks
+ * @return number of logbooks
+ */
+ public static Logbook[] assertListLogbooks(int expectedResponseCode, int expectedGreaterThanOrEqual, int expectedLessThanOrEqual, Logbook... expected) {
+ try {
+ String[] response = null;
+ Logbook[] actual = null;
+
+ response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_OLOG_LOGBOOKS);
+ ITUtil.assertResponseLength2Code(response, expectedResponseCode);
+ if (HttpURLConnection.HTTP_OK == expectedResponseCode) {
+ actual = mapper.readValue(response[1], Logbook[].class);
+ }
+
+ // expected number of items in list
+ // (if non-negative number)
+ // expectedGreaterThanOrEqual <= nbr of items <= expectedLessThanOrEqual
+ if (expectedGreaterThanOrEqual >= 0) {
+ assertTrue(actual.length >= expectedGreaterThanOrEqual);
+ }
+ if (expectedLessThanOrEqual >= 0) {
+ assertTrue(actual.length <= expectedLessThanOrEqual);
+ }
+
+ // expected content
+ if (expected != null && expected.length > 0) {
+ ITUtil.assertEqualsLogbooks(actual, expected);
+ }
+
+ return actual;
+ } catch (IOException e) {
+ fail();
+ } catch (Exception e) {
+ fail();
+ }
+ return null;
+ }
+
+ // ----------------------------------------------------------------------------------------------------
+
+ /**
+ * @see ITUtilLogbooks#assertCreateLogbook(AuthorizationChoice, String, String, int, Logbook)
+ */
+ public static Logbook assertCreateLogbook(String path, Logbook value) {
+ return assertCreateLogbook(AuthorizationChoice.ADMIN, path, object2Json(value), HttpURLConnection.HTTP_OK, LOGBOOK_NULL);
+ }
+ /**
+ * @see ITUtilLogbooks#assertCreateLogbook(AuthorizationChoice, String, String, int, Logbook)
+ */
+ public static Logbook assertCreateLogbook(AuthorizationChoice authorizationChoice, String path, Logbook value) {
+ return assertCreateLogbook(authorizationChoice, path, object2Json(value), HttpURLConnection.HTTP_OK, LOGBOOK_NULL);
+ }
+ /**
+ * @see ITUtilLogbooks#assertCreateLogbook(AuthorizationChoice, String, String, int, Logbook)
+ */
+ public static Logbook assertCreateLogbook(AuthorizationChoice authorizationChoice, String path, Logbook value, int expectedResponseCode) {
+ return assertCreateLogbook(authorizationChoice, path, object2Json(value), expectedResponseCode, LOGBOOK_NULL);
+ }
+ /**
+ * @see ITUtilLogbooks#assertCreateLogbook(AuthorizationChoice, String, String, int, Logbook)
+ */
+ public static Logbook assertCreateLogbook(AuthorizationChoice authorizationChoice, String path, String json, int expectedResponseCode) {
+ return assertCreateLogbook(authorizationChoice, path, json, expectedResponseCode, LOGBOOK_NULL);
+ }
+ /**
+ * Utility method to create or completely replace the existing logbook name with the payload data.
+ *
+ * @param authorizationChoice authorization choice (none, user, admin)
+ * @param path path
+ * @param json json
+ * @param expectedResponseCode expected response code
+ * @param expected expected response logbook
+ */
+ public static Logbook assertCreateLogbook(AuthorizationChoice authorizationChoice, String path, String json, int expectedResponseCode, Logbook expected) {
+ try {
+ String[] response = null;
+ Logbook actual = null;
+
+ response = ITUtil.runShellCommand(ITUtil.curlMethodAuthEndpointPathJson(MethodChoice.PUT, authorizationChoice, EndpointChoice.LOGBOOKS, path, json));
+ ITUtil.assertResponseLength2Code(response, expectedResponseCode);
+ if (HttpURLConnection.HTTP_OK == expectedResponseCode) {
+ actual = mapper.readValue(response[1], Logbook.class);
+ }
+
+ if (expected != null) {
+ assertEquals(expected, actual);
+ }
+
+ return actual;
+ } catch (IOException e) {
+ fail();
+ } catch (Exception e) {
+ fail();
+ }
+ return null;
+ }
+
+ // ----------------------------------------------------------------------------------------------------
+
+ /**
+ * @see ITUtilLogbooks#assertCreateLogbooks(AuthorizationChoice, String, String, int, Logbook[])
+ */
+ public static Logbook[] assertCreateLogbooks(String path, Logbook[] value) {
+ return assertCreateLogbooks(AuthorizationChoice.ADMIN, path, object2Json(value), HttpURLConnection.HTTP_OK, LOGBOOKS_NULL);
+ }
+ /**
+ * @see ITUtilLogbooks#assertCreateLogbooks(AuthorizationChoice, String, String, int, Logbook[])
+ */
+ public static Logbook[] assertCreateLogbooks(String path, Logbook[] value, int expectedResponseCode) {
+ return assertCreateLogbooks(AuthorizationChoice.ADMIN, path, object2Json(value), expectedResponseCode, LOGBOOKS_NULL);
+ }
+ /**
+ * @see ITUtilLogbooks#assertCreateLogbooks(AuthorizationChoice, String, String, int, Logbook[])
+ */
+ public static Logbook[] assertCreateLogbooks(AuthorizationChoice authorizationChoice, String path, String json, int expectedResponseCode) {
+ return assertCreateLogbooks(authorizationChoice, path, json, expectedResponseCode, LOGBOOKS_NULL);
+ }
+ /**
+ * Utility method to add the logbooks in the payload to the directory.
+ *
+ * @param authorizationChoice authorization choice (none, user, admin)
+ * @param path path
+ * @param json json
+ * @param expectedResponseCode expected response code
+ * @param expected expected response logbooks
+ */
+ public static Logbook[] assertCreateLogbooks(AuthorizationChoice authorizationChoice, String path, String json, int expectedResponseCode, Logbook[] expected) {
+ try {
+ String[] response = null;
+ Logbook[] actual = null;
+
+ response = ITUtil.runShellCommand(ITUtil.curlMethodAuthEndpointPathJson(MethodChoice.PUT, authorizationChoice, EndpointChoice.LOGBOOKS, path, json));
+ ITUtil.assertResponseLength2Code(response, expectedResponseCode);
+ if (HttpURLConnection.HTTP_OK == expectedResponseCode) {
+ actual = mapper.readValue(response[1], Logbook[].class);
+ }
+
+ if (expected != null) {
+ ITUtil.assertEqualsLogbooks(expected, actual);
+ }
+
+ return actual;
+ } catch (IOException e) {
+ fail();
+ } catch (Exception e) {
+ fail();
+ }
+ return null;
+ }
+
+ // ----------------------------------------------------------------------------------------------------
+
+ /**
+ * @see ITUtilLogbooks#assertRemoveLogbook(AuthorizationChoice, String, int)
+ */
+ public static void assertRemoveLogbook(String path) {
+ assertRemoveLogbook(AuthorizationChoice.ADMIN, path, HttpURLConnection.HTTP_OK);
+ }
+ /**
+ * Utility method to remove logbook with the given name.
+ *
+ * @param authorizationChoice authorization choice (none, user, admin)
+ * @param path path
+ * @param expectedResponseCode expected response code
+ */
+ public static void assertRemoveLogbook(AuthorizationChoice authorizationChoice, String path, int expectedResponseCode) {
+ try {
+ String[] response = null;
+
+ response = ITUtil.runShellCommand(ITUtil.curlMethodAuthEndpointPathJson(MethodChoice.DELETE, authorizationChoice, EndpointChoice.LOGBOOKS, path, null));
+ ITUtil.assertResponseLength2Code(response, expectedResponseCode);
+ } catch (IOException e) {
+ fail();
+ } catch (Exception e) {
+ fail();
+ }
+ }
+
+}
diff --git a/src/test/java/org/phoebus/olog/docker/ITUtilLogs.java b/src/test/java/org/phoebus/olog/docker/ITUtilLogs.java
new file mode 100644
index 0000000..30399ff
--- /dev/null
+++ b/src/test/java/org/phoebus/olog/docker/ITUtilLogs.java
@@ -0,0 +1,333 @@
+/*
+ * Copyright (C) 2023 European Spallation Source ERIC.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+package org.phoebus.olog.docker;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
+
+import java.io.IOException;
+import java.net.HttpURLConnection;
+
+import org.phoebus.olog.docker.ITUtil.AuthorizationChoice;
+import org.phoebus.olog.docker.ITUtil.EndpointChoice;
+import org.phoebus.olog.docker.ITUtil.MethodChoice;
+import org.phoebus.olog.entity.Log;
+import org.phoebus.olog.entity.SearchResult;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+/**
+ * Utility class to help (Docker) integration tests for Olog and Elasticsearch with focus on support test of behavior for log endpoints.
+ *
+ * @author Lars Johansson
+ *
+ * @see org.phoebus.olog.docker.ITUtil
+ */
+public class ITUtilLogs {
+
+ static final ObjectMapper mapper = new ObjectMapper();
+
+ static final Log[] LOGS_NULL = null;
+ static final Log LOG_NULL = null;
+
+ /**
+ * This class is not to be instantiated.
+ */
+ private ITUtilLogs() {
+ throw new IllegalStateException("Utility class");
+ }
+
+ // ----------------------------------------------------------------------------------------------------
+
+ /**
+ * Return string for log.
+ *
+ * @param value log
+ * @return string for log
+ */
+ static String object2Json(Log value) {
+ try {
+ return mapper.writeValueAsString(value);
+ } catch (JsonProcessingException e) {
+ fail();
+ }
+ return null;
+ }
+ /**
+ * Return string for log array.
+ *
+ * @param value log array
+ * @return string for log array
+ */
+ static String object2Json(Log[] value) {
+ try {
+ return mapper.writeValueAsString(value);
+ } catch (JsonProcessingException e) {
+ fail();
+ }
+ return null;
+ }
+
+ // ----------------------------------------------------------------------------------------------------
+
+ /**
+ * @see ITUtilLogs#assertRetrieveLog(String, int, Log)
+ */
+ public static Log assertRetrieveLog(String path, int expectedResponseCode) {
+ return assertRetrieveLog(path, expectedResponseCode, LOG_NULL);
+ }
+ /**
+ * @see ITUtilLogs#assertRetrieveLog(String, int, Log)
+ */
+ public static Log assertRetrieveLog(String path, Log expected) {
+ return assertRetrieveLog(path, HttpURLConnection.HTTP_OK, expected);
+ }
+ /**
+ * Utility method to return the log with the given name.
+ *
+ * @param path path
+ * @param expectedResponseCode expected response code
+ * @param expected expected response log
+ */
+ public static Log assertRetrieveLog(String path, int expectedResponseCode, Log expected) {
+ try {
+ String[] response = null;
+ Log actual = null;
+
+ response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_OLOG_LOGS + path);
+ ITUtil.assertResponseLength2Code(response, expectedResponseCode);
+ if (HttpURLConnection.HTTP_OK == expectedResponseCode) {
+ actual = mapper.readValue(response[1], Log.class);
+ }
+
+ if (expected != null) {
+ assertEquals(expected, actual);
+ }
+
+ return actual;
+ } catch (IOException e) {
+ fail();
+ } catch (Exception e) {
+ fail();
+ }
+ return null;
+ }
+
+ // ----------------------------------------------------------------------------------------------------
+
+ /**
+ * @see ITUtilLogs#assertListLogs(String, int, int, int, Log...)
+ */
+ public static Log[] assertListLogs(int expectedEqual, Log... expected) {
+ return assertListLogs("", HttpURLConnection.HTTP_OK, expectedEqual, expectedEqual, expected);
+ }
+ /**
+ * @see ITUtilLogs#assertListLogs(String, int, int, int, Log...)
+ */
+ public static Log[] assertListLogs(String queryString, int expectedEqual, Log... expected) {
+ return assertListLogs(queryString, HttpURLConnection.HTTP_OK, expectedEqual, expectedEqual, expected);
+ }
+ /**
+ * Utility method to return the list of all logs in the directory.
+ *
+ * @param queryString query string
+ * @param expectedResponseCode expected response code
+ * @param expectedGreaterThanOrEqual (if non-negative number) greater than or equal to this number of items
+ * @param expectedLessThanOrEqual (if non-negative number) less than or equal to this number of items
+ * @param expected expected response logs
+ * @return number of logs
+ */
+ public static Log[] assertListLogs(String queryString, int expectedResponseCode, int expectedGreaterThanOrEqual, int expectedLessThanOrEqual, Log... expected) {
+ try {
+ String[] response = null;
+ Log[] actual = null;
+
+ response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_OLOG_LOGS + queryString);
+ ITUtil.assertResponseLength2Code(response, expectedResponseCode);
+ if (HttpURLConnection.HTTP_OK == expectedResponseCode) {
+ actual = mapper.readValue(response[1], Log[].class);
+ }
+
+ // expected number of items in list
+ // (if non-negative number)
+ // expectedGreaterThanOrEqual <= nbr of items <= expectedLessThanOrEqual
+ if (expectedGreaterThanOrEqual >= 0) {
+ assertTrue(actual.length >= expectedGreaterThanOrEqual);
+ }
+ if (expectedLessThanOrEqual >= 0) {
+ assertTrue(actual.length <= expectedLessThanOrEqual);
+ }
+
+ // expected content
+ if (expected != null && expected.length > 0) {
+ ITUtil.assertEqualsLogs(actual, expected);
+ }
+
+ return actual;
+ } catch (IOException e) {
+ fail();
+ } catch (Exception e) {
+ fail();
+ }
+ return null;
+ }
+
+ // ----------------------------------------------------------------------------------------------------
+
+ /**
+ * @see ITUtilLogs#assertSearchLogs(String, int, int, int, Log...)
+ */
+ public static SearchResult assertSearchLogs(int expectedEqual, Log... expected) {
+ return assertSearchLogs("", HttpURLConnection.HTTP_OK, expectedEqual, expectedEqual, expected);
+ }
+ /**
+ * @see ITUtilLogs#assertSearchLogs(String, int, int, int, Log...)
+ */
+ public static SearchResult assertSearchLogs(String queryString, int expectedEqual, Log... expected) {
+ return assertSearchLogs(queryString, HttpURLConnection.HTTP_OK, expectedEqual, expectedEqual, expected);
+ }
+ /**
+ * Utility method to return the list of all logs in the directory.
+ *
+ * @param queryString query string
+ * @param expectedResponseCode expected response code
+ * @param expectedGreaterThanOrEqual (if non-negative number) greater than or equal to this number of items
+ * @param expectedLessThanOrEqual (if non-negative number) less than or equal to this number of items
+ * @param expected expected response logs
+ * @return number of logs
+ */
+ public static SearchResult assertSearchLogs(String queryString, int expectedResponseCode, int expectedGreaterThanOrEqual, int expectedLessThanOrEqual, Log... expected) {
+ try {
+ String[] response = null;
+ SearchResult actual = null;
+
+ response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_OLOG_LOGS + "/search" + queryString);
+ ITUtil.assertResponseLength2Code(response, expectedResponseCode);
+ if (HttpURLConnection.HTTP_OK == expectedResponseCode) {
+ actual = mapper.readValue(response[1], SearchResult.class);
+ }
+
+ // expected number of items in list
+ // (if non-negative number)
+ // expectedGreaterThanOrEqual <= nbr of items <= expectedLessThanOrEqual
+ if (expectedGreaterThanOrEqual >= 0) {
+ assertTrue(actual.getHitCount() >= expectedGreaterThanOrEqual);
+ }
+ if (expectedLessThanOrEqual >= 0) {
+ assertTrue(actual.getHitCount() <= expectedLessThanOrEqual);
+ }
+
+ // expected content
+ if (expected != null && expected.length > 0) {
+ ITUtil.assertEqualsLogs((Log[]) actual.getLogs().toArray(), expected);
+ }
+
+ return actual;
+ } catch (IOException e) {
+ fail();
+ } catch (Exception e) {
+ fail();
+ }
+ return null;
+ }
+
+ // ----------------------------------------------------------------------------------------------------
+
+ /**
+ * @see ITUtilLogs#assertCreateLog(AuthorizationChoice, String, String, int, Log)
+ */
+ public static Log assertCreateLog(String path, Log value) {
+ return assertCreateLog(AuthorizationChoice.ADMIN, path, object2Json(value), HttpURLConnection.HTTP_OK, LOG_NULL);
+ }
+ /**
+ * @see ITUtilLogs#assertCreateLog(AuthorizationChoice, String, String, int, Log)
+ */
+ public static Log assertCreateLog(AuthorizationChoice authorizationChoice, String path, Log value) {
+ return assertCreateLog(authorizationChoice, path, object2Json(value), HttpURLConnection.HTTP_OK, LOG_NULL);
+ }
+ /**
+ * @see ITUtilLogs#assertCreateLog(AuthorizationChoice, String, String, int, Log)
+ */
+ public static Log assertCreateLog(AuthorizationChoice authorizationChoice, String path, Log value, int expectedResponseCode) {
+ return assertCreateLog(authorizationChoice, path, object2Json(value), expectedResponseCode, LOG_NULL);
+ }
+ /**
+ * @see ITUtilLogs#assertCreateLog(AuthorizationChoice, String, String, int, Log)
+ */
+ public static Log assertCreateLog(AuthorizationChoice authorizationChoice, String path, String json, int expectedResponseCode) {
+ return assertCreateLog(authorizationChoice, path, json, expectedResponseCode, LOG_NULL);
+ }
+ /**
+ * Utility method to create or completely replace the existing log name with the payload data.
+ *
+ * @param authorizationChoice authorization choice (none, user, admin)
+ * @param path path
+ * @param json json
+ * @param expectedResponseCode expected response code
+ * @param expected expected response log
+ */
+ public static Log assertCreateLog(AuthorizationChoice authorizationChoice, String path, String json, int expectedResponseCode, Log expected) {
+ try {
+ String[] response = null;
+ Log actual = null;
+
+ response = ITUtil.runShellCommand(ITUtil.curlMethodAuthEndpointPathJson(MethodChoice.PUT, authorizationChoice, EndpointChoice.LOGS, path, json));
+ ITUtil.assertResponseLength2Code(response, expectedResponseCode);
+ if (HttpURLConnection.HTTP_OK == expectedResponseCode) {
+ actual = mapper.readValue(response[1], Log.class);
+ }
+
+ if (expected != null) {
+ assertEquals(expected, actual);
+ }
+
+ return actual;
+ } catch (IOException e) {
+ fail();
+ } catch (Exception e) {
+ fail();
+ }
+ return null;
+ }
+
+ // ----------------------------------------------------------------------------------------------------
+
+ /**
+ * Utility method to return curl to create log for regular user.
+ *
+ * @param logJson log json
+ * @return curl to create log
+ */
+ public static String createCurlLogForUser(String logJson) {
+ return "curl -H " + ITUtil.HEADER_JSON + " -XPUT -i " + ITUtil.HTTP_AUTH_USER_IP_PORT_OLOG_LOGS + " -d '" + logJson + "'";
+ }
+
+ /**
+ * Utility method to return curl to create log for admin user.
+ *
+ * @param logJson log json
+ * @return curl to create log
+ */
+ public static String createCurlLogForAdmin(String logJson) {
+ return "curl -H " + ITUtil.HEADER_JSON + " -XPUT -i " + ITUtil.HTTP_AUTH_ADMIN_IP_PORT_OLOG_LOGS + " -d '" + logJson + "'";
+ }
+
+}
diff --git a/src/test/java/org/phoebus/olog/docker/ITUtilProperties.java b/src/test/java/org/phoebus/olog/docker/ITUtilProperties.java
new file mode 100644
index 0000000..0e497ff
--- /dev/null
+++ b/src/test/java/org/phoebus/olog/docker/ITUtilProperties.java
@@ -0,0 +1,332 @@
+/*
+ * Copyright (C) 2023 European Spallation Source ERIC.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+package org.phoebus.olog.docker;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
+
+import java.io.IOException;
+import java.net.HttpURLConnection;
+
+import org.phoebus.olog.docker.ITUtil.AuthorizationChoice;
+import org.phoebus.olog.docker.ITUtil.EndpointChoice;
+import org.phoebus.olog.docker.ITUtil.MethodChoice;
+import org.phoebus.olog.entity.Property;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+/**
+ * Utility class to help (Docker) integration tests for Olog and Elasticsearch with focus on support test of behavior for property endpoints.
+ *
+ * @author Lars Johansson
+ *
+ * @see org.phoebus.olog.docker.ITUtil
+ */
+public class ITUtilProperties {
+
+ static final ObjectMapper mapper = new ObjectMapper();
+
+ static final Property[] PROPERTIES_NULL = null;
+ static final Property PROPERTY_NULL = null;
+
+ /**
+ * This class is not to be instantiated.
+ */
+ private ITUtilProperties() {
+ throw new IllegalStateException("Utility class");
+ }
+
+ // ----------------------------------------------------------------------------------------------------
+
+ /**
+ * Return string for property.
+ *
+ * @param value property
+ * @return string for property
+ */
+ static String object2Json(Property value) {
+ try {
+ return mapper.writeValueAsString(value);
+ } catch (JsonProcessingException e) {
+ fail();
+ }
+ return null;
+ }
+ /**
+ * Return string for property array.
+ *
+ * @param value property array
+ * @return string for property array
+ */
+ static String object2Json(Property[] value) {
+ try {
+ return mapper.writeValueAsString(value);
+ } catch (JsonProcessingException e) {
+ fail();
+ }
+ return null;
+ }
+
+ // ----------------------------------------------------------------------------------------------------
+
+ /**
+ * @see ITUtilProperties#assertRetrieveProperty(String, int, Property)
+ */
+ public static Property assertRetrieveProperty(String path, int expectedResponseCode) {
+ return assertRetrieveProperty(path, expectedResponseCode, PROPERTY_NULL);
+ }
+ /**
+ * @see ITUtilProperties#assertRetrieveProperty(String, int, Property)
+ */
+ public static Property assertRetrieveProperty(String path, Property expected) {
+ return assertRetrieveProperty(path, HttpURLConnection.HTTP_OK, expected);
+ }
+ /**
+ * Utility method to return the property with the given name.
+ *
+ * @param path path
+ * @param expectedResponseCode expected response code
+ * @param expected expected response property
+ */
+ public static Property assertRetrieveProperty(String path, int expectedResponseCode, Property expected) {
+ try {
+ String[] response = null;
+ Property actual = null;
+
+ response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_OLOG_PROPERTIES + path);
+ ITUtil.assertResponseLength2Code(response, expectedResponseCode);
+ if (HttpURLConnection.HTTP_OK == expectedResponseCode) {
+ actual = mapper.readValue(response[1], Property.class);
+ }
+
+ if (expected != null) {
+ assertEquals(expected, actual);
+ }
+
+ return actual;
+ } catch (IOException e) {
+ fail();
+ } catch (Exception e) {
+ fail();
+ }
+ return null;
+ }
+
+ // ----------------------------------------------------------------------------------------------------
+
+ /**
+ * @see ITUtilProperties#assertListProperties(String, int, int, int, Property...)
+ */
+ public static Property[] assertListProperties(int expectedEqual, Property... expected) {
+ return assertListProperties("", HttpURLConnection.HTTP_OK, expectedEqual, expectedEqual, expected);
+ }
+ /**
+ * @see ITUtilProperties#assertListProperties(String, int, int, int, Property...)
+ */
+ public static Property[] assertListProperties(String queryString, int expectedEqual, Property... expected) {
+ return assertListProperties(queryString, HttpURLConnection.HTTP_OK, expectedEqual, expectedEqual, expected);
+ }
+ /**
+ * Utility method to return the list of all properties in the directory.
+ *
+ * @param queryString query string
+ * @param expectedResponseCode expected response code
+ * @param expectedGreaterThanOrEqual (if non-negative number) greater than or equal to this number of items
+ * @param expectedLessThanOrEqual (if non-negative number) less than or equal to this number of items
+ * @param expected expected response properties
+ * @return number of properties
+ */
+ public static Property[] assertListProperties(String queryString, int expectedResponseCode, int expectedGreaterThanOrEqual, int expectedLessThanOrEqual, Property... expected) {
+ try {
+ String[] response = null;
+ Property[] actual = null;
+
+ response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_OLOG_PROPERTIES + queryString);
+ ITUtil.assertResponseLength2Code(response, expectedResponseCode);
+ if (HttpURLConnection.HTTP_OK == expectedResponseCode) {
+ actual = mapper.readValue(response[1], Property[].class);
+ }
+
+ // expected number of items in list
+ // (if non-negative number)
+ // expectedGreaterThanOrEqual <= nbr of items <= expectedLessThanOrEqual
+ if (expectedGreaterThanOrEqual >= 0) {
+ assertTrue(actual.length >= expectedGreaterThanOrEqual);
+ }
+ if (expectedLessThanOrEqual >= 0) {
+ assertTrue(actual.length <= expectedLessThanOrEqual);
+ }
+
+ // expected content
+ if (expected != null && expected.length > 0) {
+ ITUtil.assertEqualsProperties(actual, expected);
+ }
+
+ return actual;
+ } catch (IOException e) {
+ fail();
+ } catch (Exception e) {
+ fail();
+ }
+ return null;
+ }
+
+ // ----------------------------------------------------------------------------------------------------
+
+ /**
+ * @see ITUtilProperties#assertCreateProperty(AuthorizationChoice, String, String, int, Property)
+ */
+ public static Property assertCreateProperty(String path, Property value) {
+ return assertCreateProperty(AuthorizationChoice.ADMIN, path, object2Json(value), HttpURLConnection.HTTP_OK, PROPERTY_NULL);
+ }
+ /**
+ * @see ITUtilProperties#assertCreateProperty(AuthorizationChoice, String, String, int, Property)
+ */
+ public static Property assertCreateProperty(AuthorizationChoice authorizationChoice, String path, Property value) {
+ return assertCreateProperty(authorizationChoice, path, object2Json(value), HttpURLConnection.HTTP_OK, PROPERTY_NULL);
+ }
+ /**
+ * @see ITUtilProperties#assertCreateProperty(AuthorizationChoice, String, String, int, Property)
+ */
+ public static Property assertCreateProperty(AuthorizationChoice authorizationChoice, String path, Property value, int expectedResponseCode) {
+ return assertCreateProperty(authorizationChoice, path, object2Json(value), expectedResponseCode, PROPERTY_NULL);
+ }
+ /**
+ * @see ITUtilProperties#assertCreateProperty(AuthorizationChoice, String, String, int, Property)
+ */
+ public static Property assertCreateProperty(AuthorizationChoice authorizationChoice, String path, String json, int expectedResponseCode) {
+ return assertCreateProperty(authorizationChoice, path, json, expectedResponseCode, PROPERTY_NULL);
+ }
+ /**
+ * Utility method to create or completely replace the existing property name with the payload data.
+ *
+ * @param authorizationChoice authorization choice (none, user, admin)
+ * @param path path
+ * @param json json
+ * @param expectedResponseCode expected response code
+ * @param expected expected response property
+ */
+ public static Property assertCreateProperty(AuthorizationChoice authorizationChoice, String path, String json, int expectedResponseCode, Property expected) {
+ try {
+ String[] response = null;
+ Property actual = null;
+
+ response = ITUtil.runShellCommand(ITUtil.curlMethodAuthEndpointPathJson(MethodChoice.PUT, authorizationChoice, EndpointChoice.PROPERTIES, path, json));
+ ITUtil.assertResponseLength2Code(response, expectedResponseCode);
+ if (HttpURLConnection.HTTP_OK == expectedResponseCode) {
+ actual = mapper.readValue(response[1], Property.class);
+ }
+
+ if (expected != null) {
+ assertEquals(expected, actual);
+ }
+
+ return actual;
+ } catch (IOException e) {
+ fail();
+ } catch (Exception e) {
+ fail();
+ }
+ return null;
+ }
+
+ // ----------------------------------------------------------------------------------------------------
+
+ /**
+ * @see ITUtilProperties#assertCreateProperties(AuthorizationChoice, String, String, int, Property[])
+ */
+ public static Property[] assertCreateProperties(String path, Property[] value) {
+ return assertCreateProperties(AuthorizationChoice.ADMIN, path, object2Json(value), HttpURLConnection.HTTP_OK, PROPERTIES_NULL);
+ }
+ /**
+ * @see ITUtilProperties#assertCreateProperties(AuthorizationChoice, String, String, int, Property[])
+ */
+ public static Property[] assertCreateProperties(String path, Property[] value, int expectedResponseCode) {
+ return assertCreateProperties(AuthorizationChoice.ADMIN, path, object2Json(value), expectedResponseCode, PROPERTIES_NULL);
+ }
+ /**
+ * @see ITUtilProperties#assertCreateProperties(AuthorizationChoice, String, String, int, Property[])
+ */
+ public static Property[] assertCreateProperties(AuthorizationChoice authorizationChoice, String path, String json, int expectedResponseCode) {
+ return assertCreateProperties(authorizationChoice, path, json, expectedResponseCode, PROPERTIES_NULL);
+ }
+ /**
+ * Utility method to add the properties in the payload to the directory.
+ *
+ * @param authorizationChoice authorization choice (none, user, admin)
+ * @param path path
+ * @param json json
+ * @param expectedResponseCode expected response code
+ * @param expected expected response properties
+ */
+ public static Property[] assertCreateProperties(AuthorizationChoice authorizationChoice, String path, String json, int expectedResponseCode, Property[] expected) {
+ try {
+ String[] response = null;
+ Property[] actual = null;
+
+ response = ITUtil.runShellCommand(ITUtil.curlMethodAuthEndpointPathJson(MethodChoice.PUT, authorizationChoice, EndpointChoice.PROPERTIES, path, json));
+ ITUtil.assertResponseLength2Code(response, expectedResponseCode);
+ if (HttpURLConnection.HTTP_OK == expectedResponseCode) {
+ actual = mapper.readValue(response[1], Property[].class);
+ }
+
+ if (expected != null) {
+ ITUtil.assertEqualsProperties(expected, actual);
+ }
+
+ return actual;
+ } catch (IOException e) {
+ fail();
+ } catch (Exception e) {
+ fail();
+ }
+ return null;
+ }
+
+ // ----------------------------------------------------------------------------------------------------
+
+ /**
+ * @see ITUtilProperties#assertRemoveProperty(AuthorizationChoice, String, int)
+ */
+ public static void assertRemoveProperty(String path) {
+ assertRemoveProperty(AuthorizationChoice.ADMIN, path, HttpURLConnection.HTTP_OK);
+ }
+ /**
+ * Utility method to remove property with the given name.
+ *
+ * @param authorizationChoice authorization choice (none, user, admin)
+ * @param path path
+ * @param expectedResponseCode expected response code
+ */
+ public static void assertRemoveProperty(AuthorizationChoice authorizationChoice, String path, int expectedResponseCode) {
+ try {
+ String[] response = null;
+
+ response = ITUtil.runShellCommand(ITUtil.curlMethodAuthEndpointPathJson(MethodChoice.DELETE, authorizationChoice, EndpointChoice.PROPERTIES, path, null));
+ ITUtil.assertResponseLength2Code(response, expectedResponseCode);
+ } catch (IOException e) {
+ fail();
+ } catch (Exception e) {
+ fail();
+ }
+ }
+
+}
diff --git a/src/test/java/org/phoebus/olog/docker/ITUtilTags.java b/src/test/java/org/phoebus/olog/docker/ITUtilTags.java
new file mode 100644
index 0000000..9bbfe39
--- /dev/null
+++ b/src/test/java/org/phoebus/olog/docker/ITUtilTags.java
@@ -0,0 +1,325 @@
+/*
+ * Copyright (C) 2023 European Spallation Source ERIC.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+package org.phoebus.olog.docker;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
+
+import java.io.IOException;
+import java.net.HttpURLConnection;
+
+import org.phoebus.olog.docker.ITUtil.AuthorizationChoice;
+import org.phoebus.olog.docker.ITUtil.EndpointChoice;
+import org.phoebus.olog.docker.ITUtil.MethodChoice;
+import org.phoebus.olog.entity.Tag;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+/**
+ * Utility class to help (Docker) integration tests for Olog and Elasticsearch with focus on support test of behavior for tag endpoints.
+ *
+ * @author Lars Johansson
+ *
+ * @see org.phoebus.olog.docker.ITUtil
+ */
+public class ITUtilTags {
+
+ static final ObjectMapper mapper = new ObjectMapper();
+
+ static final Tag[] TAGS_NULL = null;
+ static final Tag TAG_NULL = null;
+
+ /**
+ * This class is not to be instantiated.
+ */
+ private ITUtilTags() {
+ throw new IllegalStateException("Utility class");
+ }
+
+ // ----------------------------------------------------------------------------------------------------
+
+ /**
+ * Return string for tag.
+ *
+ * @param value tag
+ * @return string for tag
+ */
+ static String object2Json(Tag value) {
+ try {
+ return mapper.writeValueAsString(value);
+ } catch (JsonProcessingException e) {
+ fail();
+ }
+ return null;
+ }
+ /**
+ * Return string for tag array.
+ *
+ * @param value tag array
+ * @return string for tag array
+ */
+ static String object2Json(Tag[] value) {
+ try {
+ return mapper.writeValueAsString(value);
+ } catch (JsonProcessingException e) {
+ fail();
+ }
+ return null;
+ }
+
+ // ----------------------------------------------------------------------------------------------------
+
+ /**
+ * @see ITUtilTags#assertRetrieveTag(String, int, Tag)
+ */
+ public static Tag assertRetrieveTag(String path, int expectedResponseCode) {
+ return assertRetrieveTag(path, expectedResponseCode, TAG_NULL);
+ }
+ /**
+ * @see ITUtilTags#assertRetrieveTag(String, int, Tag)
+ */
+ public static Tag assertRetrieveTag(String path, Tag expected) {
+ return assertRetrieveTag(path, HttpURLConnection.HTTP_OK, expected);
+ }
+ /**
+ * Utility method to return the tag with the given name.
+ *
+ * @param path path
+ * @param expectedResponseCode expected response code
+ * @param expected expected response tag
+ */
+ public static Tag assertRetrieveTag(String path, int expectedResponseCode, Tag expected) {
+ try {
+ String[] response = null;
+ Tag actual = null;
+
+ response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_OLOG_TAGS + path);
+ ITUtil.assertResponseLength2Code(response, expectedResponseCode);
+ if (HttpURLConnection.HTTP_OK == expectedResponseCode) {
+ actual = mapper.readValue(response[1], Tag.class);
+ }
+
+ if (expected != null) {
+ assertEquals(expected, actual);
+ }
+
+ return actual;
+ } catch (IOException e) {
+ fail();
+ } catch (Exception e) {
+ fail();
+ }
+ return null;
+ }
+
+ // ----------------------------------------------------------------------------------------------------
+
+ /**
+ * @see ITUtilTags#assertListTags(int, int, int, Tag...)
+ */
+ public static Tag[] assertListTags(int expectedEqual, Tag... expected) {
+ return assertListTags(HttpURLConnection.HTTP_OK, expectedEqual, expectedEqual, expected);
+ }
+ /**
+ * Utility method to return the list of all tags in the directory.
+ *
+ * @param expectedResponseCode expected response code
+ * @param expectedGreaterThanOrEqual (if non-negative number) greater than or equal to this number of items
+ * @param expectedLessThanOrEqual (if non-negative number) less than or equal to this number of items
+ * @param expected expected response tags
+ * @return number of tags
+ */
+ public static Tag[] assertListTags(int expectedResponseCode, int expectedGreaterThanOrEqual, int expectedLessThanOrEqual, Tag... expected) {
+ try {
+ String[] response = null;
+ Tag[] actual = null;
+
+ response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_OLOG_TAGS);
+ ITUtil.assertResponseLength2Code(response, expectedResponseCode);
+ if (HttpURLConnection.HTTP_OK == expectedResponseCode) {
+ actual = mapper.readValue(response[1], Tag[].class);
+ }
+
+ // expected number of items in list
+ // (if non-negative number)
+ // expectedGreaterThanOrEqual <= nbr of items <= expectedLessThanOrEqual
+ if (expectedGreaterThanOrEqual >= 0) {
+ assertTrue(actual.length >= expectedGreaterThanOrEqual);
+ }
+ if (expectedLessThanOrEqual >= 0) {
+ assertTrue(actual.length <= expectedLessThanOrEqual);
+ }
+
+ // expected content
+ if (expected != null && expected.length > 0) {
+ ITUtil.assertEqualsTags(actual, expected);
+ }
+
+ return actual;
+ } catch (IOException e) {
+ fail();
+ } catch (Exception e) {
+ fail();
+ }
+ return null;
+ }
+
+ // ----------------------------------------------------------------------------------------------------
+
+ /**
+ * @see ITUtilTags#assertCreateTag(AuthorizationChoice, String, String, int, Tag)
+ */
+ public static Tag assertCreateTag(String path, Tag value) {
+ return assertCreateTag(AuthorizationChoice.ADMIN, path, object2Json(value), HttpURLConnection.HTTP_OK, TAG_NULL);
+ }
+ /**
+ * @see ITUtilTags#assertCreateTag(AuthorizationChoice, String, String, int, Tag)
+ */
+ public static Tag assertCreateTag(AuthorizationChoice authorizationChoice, String path, Tag value) {
+ return assertCreateTag(authorizationChoice, path, object2Json(value), HttpURLConnection.HTTP_OK, TAG_NULL);
+ }
+ /**
+ * @see ITUtilTags#assertCreateTag(AuthorizationChoice, String, String, int, Tag)
+ */
+ public static Tag assertCreateTag(AuthorizationChoice authorizationChoice, String path, Tag value, int expectedResponseCode) {
+ return assertCreateTag(authorizationChoice, path, object2Json(value), expectedResponseCode, TAG_NULL);
+ }
+ /**
+ * @see ITUtilTags#assertCreateTag(AuthorizationChoice, String, String, int, Tag)
+ */
+ public static Tag assertCreateTag(AuthorizationChoice authorizationChoice, String path, String json, int expectedResponseCode) {
+ return assertCreateTag(authorizationChoice, path, json, expectedResponseCode, TAG_NULL);
+ }
+ /**
+ * Utility method to create or completely replace the existing tag name with the payload data.
+ *
+ * @param authorizationChoice authorization choice (none, user, admin)
+ * @param path path
+ * @param json json
+ * @param expectedResponseCode expected response code
+ * @param expected expected response tag
+ */
+ public static Tag assertCreateTag(AuthorizationChoice authorizationChoice, String path, String json, int expectedResponseCode, Tag expected) {
+ try {
+ String[] response = null;
+ Tag actual = null;
+
+ response = ITUtil.runShellCommand(ITUtil.curlMethodAuthEndpointPathJson(MethodChoice.PUT, authorizationChoice, EndpointChoice.TAGS, path, json));
+ ITUtil.assertResponseLength2Code(response, expectedResponseCode);
+ if (HttpURLConnection.HTTP_OK == expectedResponseCode) {
+ actual = mapper.readValue(response[1], Tag.class);
+ }
+
+ if (expected != null) {
+ assertEquals(expected, actual);
+ }
+
+ return actual;
+ } catch (IOException e) {
+ fail();
+ } catch (Exception e) {
+ fail();
+ }
+ return null;
+ }
+
+ // ----------------------------------------------------------------------------------------------------
+
+ /**
+ * @see ITUtilTags#assertCreateTags(AuthorizationChoice, String, String, int, Tag[])
+ */
+ public static Tag[] assertCreateTags(String path, Tag[] value) {
+ return assertCreateTags(AuthorizationChoice.ADMIN, path, object2Json(value), HttpURLConnection.HTTP_OK, TAGS_NULL);
+ }
+ /**
+ * @see ITUtilTags#assertCreateTags(AuthorizationChoice, String, String, int, Tag[])
+ */
+ public static Tag[] assertCreateTags(String path, Tag[] value, int expectedResponseCode) {
+ return assertCreateTags(AuthorizationChoice.ADMIN, path, object2Json(value), expectedResponseCode, TAGS_NULL);
+ }
+ /**
+ * @see ITUtilTags#assertCreateTags(AuthorizationChoice, String, String, int, Tag[])
+ */
+ public static Tag[] assertCreateTags(AuthorizationChoice authorizationChoice, String path, String json, int expectedResponseCode) {
+ return assertCreateTags(authorizationChoice, path, json, expectedResponseCode, TAGS_NULL);
+ }
+ /**
+ * Utility method to add the tags in the payload to the directory.
+ *
+ * @param authorizationChoice authorization choice (none, user, admin)
+ * @param path path
+ * @param json json
+ * @param expectedResponseCode expected response code
+ * @param expected expected response tags
+ */
+ public static Tag[] assertCreateTags(AuthorizationChoice authorizationChoice, String path, String json, int expectedResponseCode, Tag[] expected) {
+ try {
+ String[] response = null;
+ Tag[] actual = null;
+
+ response = ITUtil.runShellCommand(ITUtil.curlMethodAuthEndpointPathJson(MethodChoice.PUT, authorizationChoice, EndpointChoice.TAGS, path, json));
+ ITUtil.assertResponseLength2Code(response, expectedResponseCode);
+ if (HttpURLConnection.HTTP_OK == expectedResponseCode) {
+ actual = mapper.readValue(response[1], Tag[].class);
+ }
+
+ if (expected != null) {
+ ITUtil.assertEqualsTags(expected, actual);
+ }
+
+ return actual;
+ } catch (IOException e) {
+ fail();
+ } catch (Exception e) {
+ fail();
+ }
+ return null;
+ }
+
+ // ----------------------------------------------------------------------------------------------------
+
+ /**
+ * @see ITUtilTags#assertRemoveTag(AuthorizationChoice, String, int)
+ */
+ public static void assertRemoveTag(String path) {
+ assertRemoveTag(AuthorizationChoice.ADMIN, path, HttpURLConnection.HTTP_OK);
+ }
+ /**
+ * Utility method to remove tag with the given name.
+ *
+ * @param authorizationChoice authorization choice (none, user, admin)
+ * @param path path
+ * @param expectedResponseCode expected response code
+ */
+ public static void assertRemoveTag(AuthorizationChoice authorizationChoice, String path, int expectedResponseCode) {
+ try {
+ String[] response = null;
+
+ response = ITUtil.runShellCommand(ITUtil.curlMethodAuthEndpointPathJson(MethodChoice.DELETE, authorizationChoice, EndpointChoice.TAGS, path, null));
+ ITUtil.assertResponseLength2Code(response, expectedResponseCode);
+ } catch (IOException e) {
+ fail();
+ } catch (Exception e) {
+ fail();
+ }
+ }
+
+}
diff --git a/src/test/java/org/phoebus/olog/docker/OlogIT.java b/src/test/java/org/phoebus/olog/docker/OlogIT.java
index b21a030..92c7177 100644
--- a/src/test/java/org/phoebus/olog/docker/OlogIT.java
+++ b/src/test/java/org/phoebus/olog/docker/OlogIT.java
@@ -1,16 +1,29 @@
/*
* Copyright (C) 2021 European Spallation Source ERIC.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
package org.phoebus.olog.docker;
+import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Test;
-import org.testcontainers.containers.DockerComposeContainer;
-import org.testcontainers.containers.wait.strategy.Wait;
+import org.testcontainers.containers.ComposeContainer;
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;
-import java.io.File;
import java.io.IOException;
import java.net.HttpURLConnection;
@@ -27,7 +40,7 @@
* @author Lars Johansson
*/
@Testcontainers
-public class OlogIT {
+class OlogIT {
// Note
// ------------------------------------------------------------------------------------------------
@@ -46,12 +59,17 @@ public class OlogIT {
// ------------------------------------------------------------------------------------------------
@Container
- public static final DockerComposeContainer> ENVIRONMENT =
- new DockerComposeContainer<>(new File("docker-compose.yml"))
- .waitingFor(ITUtil.OLOG, Wait.forLogMessage(".*Started Application.*", 1));
+ public static final ComposeContainer ENVIRONMENT = ITUtil.defaultComposeContainers();
+
+ @AfterAll
+ public static void extractJacocoReport() {
+ // extract jacoco report from container file system
+ ITUtil.extractJacocoReport(ENVIRONMENT,
+ ITUtil.JACOCO_TARGET_PREFIX + OlogIT.class.getSimpleName() + ITUtil.JACOCO_TARGET_SUFFIX);
+ }
@Test
- public void ologUp() {
+ void ologUp() {
try {
String address = ITUtil.HTTP_IP_PORT_OLOG;
int responseCode = ITUtil.doGet(address);
@@ -62,7 +80,7 @@ public void ologUp() {
}
}
@Test
- public void ologUpTags() {
+ void ologUpTags() {
try {
String address = ITUtil.HTTP_IP_PORT_OLOG + "/tags";
int responseCode = ITUtil.doGet(address);
@@ -73,7 +91,7 @@ public void ologUpTags() {
}
}
@Test
- public void ologUpLogbooks() {
+ void ologUpLogbooks() {
try {
String address = ITUtil.HTTP_IP_PORT_OLOG + "/logbooks";
int responseCode = ITUtil.doGet(address);
@@ -84,7 +102,7 @@ public void ologUpLogbooks() {
}
}
@Test
- public void ologUpProperties() {
+ void ologUpProperties() {
try {
String address = ITUtil.HTTP_IP_PORT_OLOG + "/properties";
int responseCode = ITUtil.doGet(address);
@@ -95,7 +113,7 @@ public void ologUpProperties() {
}
}
@Test
- public void ologUpLogs() {
+ void ologUpLogs() {
try {
String address = ITUtil.HTTP_IP_PORT_OLOG + "/logs";
int responseCode = ITUtil.doGet(address);
@@ -106,7 +124,7 @@ public void ologUpLogs() {
}
}
@Test
- public void ologUpConfiguration() {
+ void ologUpConfiguration() {
try {
String address = ITUtil.HTTP_IP_PORT_OLOG + "/configuration";
int responseCode = ITUtil.doGet(address);
@@ -117,7 +135,7 @@ public void ologUpConfiguration() {
}
}
@Test
- public void ologUpAttachment() {
+ void ologUpAttachment() {
try {
String address = ITUtil.HTTP_IP_PORT_OLOG + "/attachment";
int responseCode = ITUtil.doGet(address);
@@ -128,82 +146,4 @@ public void ologUpAttachment() {
}
}
- @Test
- public void elasticsearchUp() {
- try {
- String address = ITUtil.HTTP_IP_PORT_ELASTICSEARCH;
- int responseCode = ITUtil.doGet(address);
-
- assertEquals(HttpURLConnection.HTTP_OK, responseCode);
- } catch (IOException e) {
- fail();
- }
- }
- @Test
- public void elasticsearchUpHealthcheck() {
- try {
- String address = ITUtil.HTTP_IP_PORT_ELASTICSEARCH + "/_cat/health";
- int responseCode = ITUtil.doGet(address);
-
- assertEquals(HttpURLConnection.HTTP_OK, responseCode);
- } catch (IOException e) {
- fail();
- }
- }
- @Test
- public void elasticsearchUpTags() {
- try {
- String address = ITUtil.HTTP_IP_PORT_ELASTICSEARCH + "/olog_tags";
- int responseCode = ITUtil.doGet(address);
-
- assertEquals(HttpURLConnection.HTTP_OK, responseCode);
- } catch (IOException e) {
- fail();
- }
- }
- @Test
- public void elasticsearchUpLogbooks() {
- try {
- String address = ITUtil.HTTP_IP_PORT_ELASTICSEARCH + "/olog_logbooks";
- int responseCode = ITUtil.doGet(address);
-
- assertEquals(HttpURLConnection.HTTP_OK, responseCode);
- } catch (IOException e) {
- fail();
- }
- }
- @Test
- public void elasticsearchUpProperties() {
- try {
- String address = ITUtil.HTTP_IP_PORT_ELASTICSEARCH + "/olog_properties";
- int responseCode = ITUtil.doGet(address);
-
- assertEquals(HttpURLConnection.HTTP_OK, responseCode);
- } catch (IOException e) {
- fail();
- }
- }
- @Test
- public void elasticsearchUpSequence() {
- try {
- String address = ITUtil.HTTP_IP_PORT_ELASTICSEARCH + "/olog_sequence";
- int responseCode = ITUtil.doGet(address);
-
- assertEquals(HttpURLConnection.HTTP_NOT_FOUND, responseCode);
- } catch (IOException e) {
- fail();
- }
- }
- @Test
- public void elasticsearchUpLogs() {
- try {
- String address = ITUtil.HTTP_IP_PORT_ELASTICSEARCH + "/olog_logs";
- int responseCode = ITUtil.doGet(address);
-
- assertEquals(HttpURLConnection.HTTP_NOT_FOUND, responseCode);
- } catch (IOException e) {
- fail();
- }
- }
-
}
diff --git a/src/test/java/org/phoebus/olog/docker/OlogLogbooksIT.java b/src/test/java/org/phoebus/olog/docker/OlogLogbooksIT.java
index 7a60073..c9e3524 100644
--- a/src/test/java/org/phoebus/olog/docker/OlogLogbooksIT.java
+++ b/src/test/java/org/phoebus/olog/docker/OlogLogbooksIT.java
@@ -1,26 +1,37 @@
/*
* Copyright (C) 2021 European Spallation Source ERIC.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
package org.phoebus.olog.docker;
-import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
+import org.phoebus.olog.docker.ITUtil.AuthorizationChoice;
import org.phoebus.olog.entity.Logbook;
import org.phoebus.olog.entity.State;
-import org.testcontainers.containers.DockerComposeContainer;
-import org.testcontainers.containers.wait.strategy.Wait;
+import org.testcontainers.containers.ComposeContainer;
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;
-import java.io.File;
import java.io.IOException;
import java.net.HttpURLConnection;
import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
/**
@@ -36,7 +47,7 @@
* @see org.phoebus.olog.LogbooksResource
*/
@Testcontainers
-public class OlogLogbooksIT {
+class OlogLogbooksIT {
// Note
// ------------------------------------------------------------------------------------------------
@@ -57,25 +68,21 @@ public class OlogLogbooksIT {
// Olog - Service Documentation
// https://olog.readthedocs.io/en/latest/
// ------------------------------------------------------------------------------------------------
- // OLOG API LogbooksResource
- // -------------------- --------------------
- // Retrieve a Logbook .../logbooks/ (GET) findByTitle(String)
- // List Logbooks .../logbooks (GET) findAll()
- // Create a Logbook .../logbooks/ (PUT) createLogbook(String, Logbook, Principal)
- // Create Logbooks .../logbooks (PUT) updateLogbooks(List)
- // Remove Logbook .../logbooks/ (DELETE) deleteLogbook(String)
+ // OLOG API LogbooksResource
+ // -------------------- --------------------
+ // Retrieve a Logbook .../logbooks/ (GET) findByTitle(String)
+ // List Logbooks .../logbooks (GET) findAll()
+ // Create a Logbook .../logbooks/ (PUT) createLogbook(String, Logbook, Principal)
+ // Create Logbooks .../logbooks (PUT) updateLogbooks(List)
+ // Remove Logbook .../logbooks/ (DELETE) deleteLogbook(String)
// ------------------------------------------------------------------------------------------------
- static final String LOGBOOKS = "/logbooks";
-
- static final String HTTP_IP_PORT_OLOG_LOGBOOKS = ITUtil.HTTP + ITUtil.IP_PORT_OLOG + LOGBOOKS;
- static final String HTTP_AUTH_USER_IP_PORT_OLOG_LOGBOOKS = ITUtil.HTTP + ITUtil.AUTH_USER + "@" + ITUtil.IP_PORT_OLOG + LOGBOOKS;
- static final String HTTP_AUTH_ADMIN_IP_PORT_OLOG_LOGBOOKS = ITUtil.HTTP + ITUtil.AUTH_ADMIN + "@" + ITUtil.IP_PORT_OLOG + LOGBOOKS;
-
// test data
// logbooks l1 - l10, owner admin, state Active - Inactive
// logbooks l1 - l2 owner admin, state Inactive
+ static Logbook[] default_logbooks;
+
static Logbook logbook_l1_owner_a_state_a;
static Logbook logbook_l2_owner_a_state_a;
static Logbook logbook_l3_owner_a_state_a;
@@ -91,12 +98,14 @@ public class OlogLogbooksIT {
static Logbook logbook_l10_owner_a_state_i;
@Container
- public static final DockerComposeContainer> ENVIRONMENT =
- new DockerComposeContainer<>(new File("docker-compose.yml"))
- .waitingFor(ITUtil.OLOG, Wait.forLogMessage(".*Started Application.*", 1));
+ public static final ComposeContainer ENVIRONMENT = ITUtil.defaultComposeContainers();
@BeforeAll
public static void setupObjects() {
+ default_logbooks = new Logbook[] {
+ new Logbook("operations", "olog-logs", State.Active),
+ new Logbook("controls", null, State.Active)};
+
logbook_l1_owner_a_state_a = new Logbook("l1", "admin", State.Active);
logbook_l2_owner_a_state_a = new Logbook("l2", "admin", State.Active);
logbook_l3_owner_a_state_a = new Logbook("l3", "admin", State.Active);
@@ -114,6 +123,8 @@ public static void setupObjects() {
@AfterAll
public static void tearDownObjects() {
+ default_logbooks = null;
+
logbook_l1_owner_a_state_a = null;
logbook_l2_owner_a_state_a = null;
logbook_l3_owner_a_state_a = null;
@@ -129,8 +140,15 @@ public static void tearDownObjects() {
logbook_l10_owner_a_state_i = null;
}
+ @AfterAll
+ public static void extractJacocoReport() {
+ // extract jacoco report from container file system
+ ITUtil.extractJacocoReport(ENVIRONMENT,
+ ITUtil.JACOCO_TARGET_PREFIX + OlogLogbooksIT.class.getSimpleName() + ITUtil.JACOCO_TARGET_SUFFIX);
+ }
+
@Test
- public void ologUp() {
+ void ologUp() {
try {
String address = ITUtil.HTTP_IP_PORT_OLOG;
int responseCode = ITUtil.doGet(address);
@@ -145,7 +163,7 @@ public void ologUp() {
* Test {@link org.phoebus.olog.OlogResourceDescriptors#LOGBOOK_RESOURCE_URI}.
*/
@Test
- public void handleLogbookRetrieveCheck() {
+ void handleLogbookRetrieveCheck() {
// what
// check(s) for retrieve logbook
// e.g.
@@ -157,19 +175,14 @@ public void handleLogbookRetrieveCheck() {
// Create Logbooks
// Remove Logbook
- try {
- String[] response = ITUtil.doGetJson(HTTP_IP_PORT_OLOG_LOGBOOKS + "/l11");
- ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_NOT_FOUND);
- } catch (IOException e) {
- fail();
- }
+ ITUtilLogbooks.assertRetrieveLogbook("/l11", HttpURLConnection.HTTP_NOT_FOUND);
}
/**
* Test {@link org.phoebus.olog.OlogResourceDescriptors#LOGBOOK_RESOURCE_URI}.
*/
@Test
- public void handleLogbookRemoveCheck() {
+ void handleLogbookRemoveCheck() {
// what
// check(s) for remove logbook
// e.g.
@@ -181,27 +194,21 @@ public void handleLogbookRemoveCheck() {
// Create Logbooks
// x Remove Logbook
- try {
- // might be both 401, 404
- // 401 UNAUTHORIZED
- // 404 NOT_FOUND
- String[] response = ITUtil.runShellCommand(deleteCurlLogbookForUser("l11"));
- ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_NOT_FOUND);
-
- response = ITUtil.runShellCommand(deleteCurlLogbookForAdmin("l11"));
- ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_NOT_FOUND);
- } catch (IOException e) {
- fail();
- } catch (Exception e) {
- fail();
- }
+ // might be both 401, 404
+ // 401 UNAUTHORIZED
+ // 404 NOT_FOUND
+
+ // check permissions
+
+ ITUtilLogbooks.assertRemoveLogbook(AuthorizationChoice.USER, "/l11", HttpURLConnection.HTTP_NOT_FOUND);
+ ITUtilLogbooks.assertRemoveLogbook(AuthorizationChoice.ADMIN, "/l11", HttpURLConnection.HTTP_NOT_FOUND);
}
/**
* Test {@link org.phoebus.olog.OlogResourceDescriptors#LOGBOOK_RESOURCE_URI}.
*/
@Test
- public void handleLogbookCreateCheckJson() {
+ void handleLogbookCreateCheckJson() {
// what
// check(s) for create logbook
// e.g.
@@ -228,48 +235,32 @@ public void handleLogbookCreateCheckJson() {
String json_incomplete8 = "}";
String json_incomplete9 = "\"";
- String json_logbook_l1_name_na = "{\"na\":\"l1\",\"owner\":\"admin\",\"state\":\"Active\"}";
+ String json_logbook_l1_name_na = "{\"na\":\"l1\",\"owner\":\"admin\",\"state\":\"Active\"}";
try {
- String[] response = ITUtil.doGetJson(HTTP_IP_PORT_OLOG_LOGBOOKS);
- ITUtil.assertResponseLength2CodeOKContent(response, ITUtil.EMPTY_JSON);
-
- response = ITUtil.runShellCommand(createCurlLogbookForAdmin("l1", json_incomplete1));
- ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_BAD_REQUEST);
-
- response = ITUtil.runShellCommand(createCurlLogbookForAdmin("l1", json_incomplete2));
- ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_BAD_REQUEST);
+ ITUtilLogbooks.assertListLogbooks(2,
+ default_logbooks[1],
+ default_logbooks[0]);
+
+ ITUtilLogbooks.assertCreateLogbook(AuthorizationChoice.ADMIN, "/l1", json_incomplete1, HttpURLConnection.HTTP_BAD_REQUEST);
+ ITUtilLogbooks.assertCreateLogbook(AuthorizationChoice.ADMIN, "/l1", json_incomplete2, HttpURLConnection.HTTP_BAD_REQUEST);
+ ITUtilLogbooks.assertCreateLogbook(AuthorizationChoice.ADMIN, "/l1", json_incomplete3, HttpURLConnection.HTTP_BAD_REQUEST);
+ ITUtilLogbooks.assertCreateLogbook(AuthorizationChoice.ADMIN, "/l1", json_incomplete4, HttpURLConnection.HTTP_BAD_REQUEST);
+ ITUtilLogbooks.assertCreateLogbook(AuthorizationChoice.ADMIN, "/l1", json_incomplete5, HttpURLConnection.HTTP_BAD_REQUEST);
+ ITUtilLogbooks.assertCreateLogbook(AuthorizationChoice.ADMIN, "/l1", json_incomplete6, HttpURLConnection.HTTP_BAD_REQUEST);
+ ITUtilLogbooks.assertCreateLogbook(AuthorizationChoice.ADMIN, "/l1", json_incomplete7, HttpURLConnection.HTTP_BAD_REQUEST);
+ ITUtilLogbooks.assertCreateLogbook(AuthorizationChoice.ADMIN, "/l1", json_incomplete8, HttpURLConnection.HTTP_BAD_REQUEST);
+ ITUtilLogbooks.assertCreateLogbook(AuthorizationChoice.ADMIN, "/l1", json_incomplete9, HttpURLConnection.HTTP_BAD_REQUEST);
+ ITUtilLogbooks.assertCreateLogbook(AuthorizationChoice.ADMIN, "/l1", json_logbook_l1_name_na, HttpURLConnection.HTTP_BAD_REQUEST);
- response = ITUtil.runShellCommand(createCurlLogbookForAdmin("l1", json_incomplete3));
- ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_BAD_REQUEST);
-
- response = ITUtil.runShellCommand(createCurlLogbookForAdmin("l1", json_incomplete4));
- ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_BAD_REQUEST);
-
- response = ITUtil.runShellCommand(createCurlLogbookForAdmin("l1", json_incomplete5));
- ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_BAD_REQUEST);
-
- response = ITUtil.runShellCommand(createCurlLogbookForAdmin("l1", json_incomplete6));
- ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_BAD_REQUEST);
-
- response = ITUtil.runShellCommand(createCurlLogbookForAdmin("l1", json_incomplete7));
- ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_BAD_REQUEST);
-
- response = ITUtil.runShellCommand(createCurlLogbookForAdmin("l1", json_incomplete8));
- ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_BAD_REQUEST);
-
- response = ITUtil.runShellCommand(createCurlLogbookForAdmin("l1", json_incomplete9));
- ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_BAD_REQUEST);
-
- response = ITUtil.runShellCommand(createCurlLogbookForAdmin("l1", json_logbook_l1_name_na));
- ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_BAD_REQUEST);
+ // refresh elastic indices
+ ITUtil.assertRefreshElasticIndices();
- response = ITUtil.doGetJson(HTTP_IP_PORT_OLOG_LOGBOOKS);
- ITUtil.assertResponseLength2CodeOKContent(response, ITUtil.EMPTY_JSON);
+ ITUtilLogbooks.assertListLogbooks(2,
+ default_logbooks[1],
+ default_logbooks[0]);
} catch (IOException e) {
fail();
- } catch (InterruptedException e) {
- fail();
} catch (Exception e) {
fail();
}
@@ -279,7 +270,7 @@ public void handleLogbookCreateCheckJson() {
* Test {@link org.phoebus.olog.OlogResourceDescriptors#LOGBOOK_RESOURCE_URI}.
*/
@Test
- public void handleLogbookCreateCheck() {
+ void handleLogbookCreateCheck() {
// what
// check(s) for create logbook
// e.g.
@@ -298,47 +289,34 @@ public void handleLogbookCreateCheck() {
Logbook logbook_check = new Logbook();
- ObjectMapper mapper = new ObjectMapper();
-
- try {
- String[] response = ITUtil.doGetJson(HTTP_IP_PORT_OLOG_LOGBOOKS);
- ITUtil.assertResponseLength2CodeOKContent(response, ITUtil.EMPTY_JSON);
-
- // response = ITUtil.runShellCommand(createCurlLogbookForUser("l1", mapper.writeValueAsString(logbook_l1_owner_a_state_a)));
- // ITUtil.assertResponseLength2Code(HttpURLConnection.HTTP_UNAUTHORIZED, response);
+ ITUtilLogbooks.assertListLogbooks(2,
+ default_logbooks[1],
+ default_logbooks[0]);
- response = ITUtil.runShellCommand(createCurlLogbookForUser("asdf", mapper.writeValueAsString(logbook_check)));
- ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_BAD_REQUEST);
+ // check permissions
+ // ITUtilLogbooks.assertCreateLogbook(AuthorizationChoice.USER, "/l1", logbook_l1_owner_a_state_a, HttpURLConnection.HTTP_UNAUTHORIZED);
- response = ITUtil.runShellCommand(createCurlLogbookForAdmin("asdf", mapper.writeValueAsString(logbook_check)));
- ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_BAD_REQUEST);
+ ITUtilLogbooks.assertCreateLogbook(AuthorizationChoice.USER, "/asdf", logbook_check, HttpURLConnection.HTTP_BAD_REQUEST);
+ ITUtilLogbooks.assertCreateLogbook(AuthorizationChoice.ADMIN, "/asdf", logbook_check, HttpURLConnection.HTTP_BAD_REQUEST);
- logbook_check.setName(null);
+ logbook_check.setName(null);
- response = ITUtil.runShellCommand(createCurlLogbookForAdmin("asdf", mapper.writeValueAsString(logbook_check)));
- ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_BAD_REQUEST);
+ ITUtilLogbooks.assertCreateLogbook(AuthorizationChoice.ADMIN, "/asdf", logbook_check, HttpURLConnection.HTTP_BAD_REQUEST);
- logbook_check.setName("");
+ logbook_check.setName("");
- response = ITUtil.runShellCommand(createCurlLogbookForAdmin("asdf", mapper.writeValueAsString(logbook_check)));
- ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_BAD_REQUEST);
+ ITUtilLogbooks.assertCreateLogbook(AuthorizationChoice.ADMIN, "/asdf", logbook_check, HttpURLConnection.HTTP_BAD_REQUEST);
- response = ITUtil.doGetJson(HTTP_IP_PORT_OLOG_LOGBOOKS);
- ITUtil.assertResponseLength2CodeOKContent(response, ITUtil.EMPTY_JSON);
- } catch (IOException e) {
- fail();
- } catch (InterruptedException e) {
- fail();
- } catch (Exception e) {
- fail();
- }
+ ITUtilLogbooks.assertListLogbooks(2,
+ default_logbooks[1],
+ default_logbooks[0]);
}
/**
* Test {@link org.phoebus.olog.OlogResourceDescriptors#LOGBOOK_RESOURCE_URI}.
*/
@Test
- public void handleLogbook() {
+ void handleLogbook() {
// what
// user with required role
// create tag
@@ -351,46 +329,38 @@ public void handleLogbook() {
// Create Logbooks
// x Remove Logbook
- ObjectMapper mapper = new ObjectMapper();
-
try {
- String[] response = ITUtil.doGetJson(HTTP_IP_PORT_OLOG_LOGBOOKS);
- ITUtil.assertResponseLength2CodeOKContent(response, ITUtil.EMPTY_JSON);
+ ITUtilLogbooks.assertListLogbooks(2,
+ default_logbooks[1],
+ default_logbooks[0]);
- response = ITUtil.runShellCommand(createCurlLogbookForAdmin("l1", mapper.writeValueAsString(logbook_l1_owner_a_state_a)));
- ITUtil.assertResponseLength2CodeOK(response);
- assertTrue(logbook_l1_owner_a_state_a.equals(mapper.readValue(response[1], Logbook.class)));
+ ITUtilLogbooks.assertCreateLogbook("/l1", logbook_l1_owner_a_state_a);
// refresh elastic indices
- response = ITUtil.refreshElasticIndices();
- ITUtil.assertResponseLength2CodeOK(response);
+ ITUtil.assertRefreshElasticIndices();
+
+ ITUtilLogbooks.assertListLogbooks(3,
+ default_logbooks[1],
+ logbook_l1_owner_a_state_a,
+ default_logbooks[0]);
- response = ITUtil.doGetJson(HTTP_IP_PORT_OLOG_LOGBOOKS);
- ITUtil.assertResponseLength2CodeOK(response);
- ITUtil.assertEqualsLogbooks(
- mapper.readValue(response[1], Logbook[].class),
- logbook_l1_owner_a_state_a);
+ ITUtilLogbooks.assertRetrieveLogbook("/l1", logbook_l1_owner_a_state_a);
- response = ITUtil.doGetJson(HTTP_IP_PORT_OLOG_LOGBOOKS + "/l1");
- ITUtil.assertResponseLength2CodeOK(response);
- assertTrue(logbook_l1_owner_a_state_a.equals(mapper.readValue(response[1], Logbook.class)));
+ // check permissions
+ // ITUtilLogbooks.assertRemoveLogbook(AuthorizationChoice.USER, "/l1", HttpURLConnection.HTTP_UNAUTHORIZED);
- // response = ITUtil.runShellCommand(deleteCurlLogbookForUser("l1"));
- // ITUtil.assertResponseLength2Code(HttpURLConnection.HTTP_UNAUTHORIZED, response);
+ ITUtilLogbooks.assertRemoveLogbook("/l1");
- response = ITUtil.runShellCommand(deleteCurlLogbookForAdmin("l1"));
- ITUtil.assertResponseLength2CodeOK(response);
+ // refresh elastic indices
+ ITUtil.assertRefreshElasticIndices();
- response = ITUtil.doGetJson(HTTP_IP_PORT_OLOG_LOGBOOKS + "/l1");
- ITUtil.assertResponseLength2CodeOK(response);
- assertTrue(logbook_l1_owner_a_state_i.equals(mapper.readValue(response[1], Logbook.class)));
+ ITUtilLogbooks.assertRetrieveLogbook("/l1", logbook_l1_owner_a_state_i);
- response = ITUtil.doGetJson(HTTP_IP_PORT_OLOG_LOGBOOKS);
- ITUtil.assertResponseLength2CodeOKContent(response, ITUtil.EMPTY_JSON);
+ ITUtilLogbooks.assertListLogbooks(2,
+ default_logbooks[1],
+ default_logbooks[0]);
} catch (IOException e) {
fail();
- } catch (InterruptedException e) {
- fail();
} catch (Exception e) {
fail();
}
@@ -400,7 +370,7 @@ public void handleLogbook() {
* Test {@link org.phoebus.olog.OlogResourceDescriptors#LOGBOOK_RESOURCE_URI}.
*/
@Test
- public void handleLogbook2() {
+ void handleLogbook2() {
// what
// create logbooks, one by one
// --------------------------------------------------------------------------------
@@ -412,65 +382,50 @@ public void handleLogbook2() {
// Create Logbooks
// x Remove Logbook
- ObjectMapper mapper = new ObjectMapper();
-
try {
- String[] response = ITUtil.doGetJson(HTTP_IP_PORT_OLOG_LOGBOOKS);
- ITUtil.assertResponseLength2CodeOKContent(response, ITUtil.EMPTY_JSON);
+ ITUtilLogbooks.assertListLogbooks(2,
+ default_logbooks[1],
+ default_logbooks[0]);
- response = ITUtil.runShellCommand(createCurlLogbookForAdmin("l1", mapper.writeValueAsString(logbook_l1_owner_a_state_a)));
- ITUtil.assertResponseLength2CodeOK(response);
- assertTrue(logbook_l1_owner_a_state_a.equals(mapper.readValue(response[1], Logbook.class)));
-
- response = ITUtil.runShellCommand(createCurlLogbookForAdmin("l2", mapper.writeValueAsString(logbook_l2_owner_a_state_a)));
- ITUtil.assertResponseLength2CodeOK(response);
- assertTrue(logbook_l2_owner_a_state_a.equals(mapper.readValue(response[1], Logbook.class)));
+ ITUtilLogbooks.assertCreateLogbook("/l1", logbook_l1_owner_a_state_a);
+ ITUtilLogbooks.assertCreateLogbook("/l2", logbook_l2_owner_a_state_a);
// refresh elastic indices
- response = ITUtil.refreshElasticIndices();
- ITUtil.assertResponseLength2CodeOK(response);
+ ITUtil.assertRefreshElasticIndices();
- response = ITUtil.doGetJson(HTTP_IP_PORT_OLOG_LOGBOOKS);
- ITUtil.assertResponseLength2CodeOK(response);
- ITUtil.assertEqualsLogbooks(
- mapper.readValue(response[1], Logbook[].class),
+ ITUtilLogbooks.assertListLogbooks(4,
+ default_logbooks[1],
logbook_l1_owner_a_state_a,
- logbook_l2_owner_a_state_a);
+ logbook_l2_owner_a_state_a,
+ default_logbooks[0]);
- response = ITUtil.doGetJson(HTTP_IP_PORT_OLOG_LOGBOOKS + "/l1");
- ITUtil.assertResponseLength2CodeOK(response);
- assertTrue(logbook_l1_owner_a_state_a.equals(mapper.readValue(response[1], Logbook.class)));
+ ITUtilLogbooks.assertRetrieveLogbook("/l1", logbook_l1_owner_a_state_a);
+ ITUtilLogbooks.assertRetrieveLogbook("/l2", logbook_l2_owner_a_state_a);
- response = ITUtil.doGetJson(HTTP_IP_PORT_OLOG_LOGBOOKS + "/l2");
- ITUtil.assertResponseLength2CodeOK(response);
- assertTrue(logbook_l2_owner_a_state_a.equals(mapper.readValue(response[1], Logbook.class)));
+ ITUtilLogbooks.assertRemoveLogbook("/l1");
+
+ // refresh elastic indices
+ ITUtil.assertRefreshElasticIndices();
- response = ITUtil.runShellCommand(deleteCurlLogbookForAdmin("l1"));
- ITUtil.assertResponseLength2CodeOK(response);
+ ITUtilLogbooks.assertListLogbooks(3,
+ default_logbooks[1],
+ logbook_l2_owner_a_state_a,
+ default_logbooks[0]);
- response = ITUtil.doGetJson(HTTP_IP_PORT_OLOG_LOGBOOKS);
- ITUtil.assertResponseLength2CodeOK(response);
- ITUtil.assertEqualsLogbooks(
- mapper.readValue(response[1], Logbook[].class),
- logbook_l2_owner_a_state_a);
+ ITUtilLogbooks.assertRetrieveLogbook("/l1", logbook_l1_owner_a_state_i);
- response = ITUtil.doGetJson(HTTP_IP_PORT_OLOG_LOGBOOKS + "/l1");
- ITUtil.assertResponseLength2CodeOK(response);
- assertTrue(logbook_l1_owner_a_state_i.equals(mapper.readValue(response[1], Logbook.class)));
+ ITUtilLogbooks.assertRemoveLogbook("/l2");
- response = ITUtil.runShellCommand(deleteCurlLogbookForAdmin("l2"));
- ITUtil.assertResponseLength2CodeOK(response);
+ // refresh elastic indices
+ ITUtil.assertRefreshElasticIndices();
- response = ITUtil.doGetJson(HTTP_IP_PORT_OLOG_LOGBOOKS + "/l2");
- ITUtil.assertResponseLength2CodeOK(response);
- assertTrue(logbook_l2_owner_a_state_i.equals(mapper.readValue(response[1], Logbook.class)));
+ ITUtilLogbooks.assertRetrieveLogbook("/l2", logbook_l2_owner_a_state_i);
- response = ITUtil.doGetJson(HTTP_IP_PORT_OLOG_LOGBOOKS);
- ITUtil.assertResponseLength2CodeOKContent(response, ITUtil.EMPTY_JSON);
+ ITUtilLogbooks.assertListLogbooks(2,
+ default_logbooks[1],
+ default_logbooks[0]);
} catch (IOException e) {
fail();
- } catch (InterruptedException e) {
- fail();
} catch (Exception e) {
fail();
}
@@ -480,7 +435,7 @@ public void handleLogbook2() {
* Test {@link org.phoebus.olog.OlogResourceDescriptors#LOGBOOK_RESOURCE_URI}.
*/
@Test
- public void handleLogbook3ChangeState() {
+ void handleLogbook3ChangeState() {
// what
// replace logbook, change state
// --------------------------------------------------------------------------------
@@ -492,53 +447,46 @@ public void handleLogbook3ChangeState() {
// Create Logbooks
// x Remove Logbook
- ObjectMapper mapper = new ObjectMapper();
-
try {
- String[] response = ITUtil.doGetJson(HTTP_IP_PORT_OLOG_LOGBOOKS);
- ITUtil.assertResponseLength2CodeOKContent(response, ITUtil.EMPTY_JSON);
+ ITUtilLogbooks.assertListLogbooks(2,
+ default_logbooks[1],
+ default_logbooks[0]);
- response = ITUtil.runShellCommand(createCurlLogbookForAdmin("l1", mapper.writeValueAsString(logbook_l1_owner_a_state_a)));
- ITUtil.assertResponseLength2CodeOK(response);
- assertTrue(logbook_l1_owner_a_state_a.equals(mapper.readValue(response[1], Logbook.class)));
+ ITUtilLogbooks.assertCreateLogbook("/l1", logbook_l1_owner_a_state_a);
// refresh elastic indices
- response = ITUtil.refreshElasticIndices();
- ITUtil.assertResponseLength2CodeOK(response);
+ ITUtil.assertRefreshElasticIndices();
- response = ITUtil.doGetJson(HTTP_IP_PORT_OLOG_LOGBOOKS);
- ITUtil.assertResponseLength2CodeOK(response);
- ITUtil.assertEqualsLogbooks(
- mapper.readValue(response[1], Logbook[].class),
- logbook_l1_owner_a_state_a);
+ ITUtilLogbooks.assertListLogbooks(3,
+ default_logbooks[1],
+ logbook_l1_owner_a_state_a,
+ default_logbooks[0]);
+
+ ITUtilLogbooks.assertRetrieveLogbook("/l1", logbook_l1_owner_a_state_a);
- response = ITUtil.doGetJson(HTTP_IP_PORT_OLOG_LOGBOOKS + "/l1");
- ITUtil.assertResponseLength2CodeOK(response);
- assertTrue(logbook_l1_owner_a_state_a.equals(mapper.readValue(response[1], Logbook.class)));
+ ITUtilLogbooks.assertCreateLogbook("/l1", logbook_l1_owner_a_state_i);
+
+ // refresh elastic indices
+ ITUtil.assertRefreshElasticIndices();
- response = ITUtil.runShellCommand(createCurlLogbookForAdmin("l1", mapper.writeValueAsString(logbook_l1_owner_a_state_i)));
- ITUtil.assertResponseLength2CodeOK(response);
+ ITUtilLogbooks.assertListLogbooks(2,
+ default_logbooks[1],
+ default_logbooks[0]);
- response = ITUtil.doGetJson(HTTP_IP_PORT_OLOG_LOGBOOKS);
- ITUtil.assertResponseLength2CodeOKContent(response, ITUtil.EMPTY_JSON);
+ ITUtilLogbooks.assertRetrieveLogbook("/l1", logbook_l1_owner_a_state_i);
- response = ITUtil.doGetJson(HTTP_IP_PORT_OLOG_LOGBOOKS + "/l1");
- ITUtil.assertResponseLength2CodeOK(response);
- assertTrue(logbook_l1_owner_a_state_i.equals(mapper.readValue(response[1], Logbook.class)));
+ ITUtilLogbooks.assertRemoveLogbook("/l1");
- response = ITUtil.runShellCommand(deleteCurlLogbookForAdmin("l1"));
- ITUtil.assertResponseLength2CodeOK(response);
+ // refresh elastic indices
+ ITUtil.assertRefreshElasticIndices();
- response = ITUtil.doGetJson(HTTP_IP_PORT_OLOG_LOGBOOKS + "/l1");
- ITUtil.assertResponseLength2CodeOK(response);
- assertTrue(logbook_l1_owner_a_state_i.equals(mapper.readValue(response[1], Logbook.class)));
+ ITUtilLogbooks.assertRetrieveLogbook("/l1", logbook_l1_owner_a_state_i);
- response = ITUtil.doGetJson(HTTP_IP_PORT_OLOG_LOGBOOKS);
- ITUtil.assertResponseLength2CodeOKContent(response, ITUtil.EMPTY_JSON);
+ ITUtilLogbooks.assertListLogbooks(2,
+ default_logbooks[1],
+ default_logbooks[0]);
} catch (IOException e) {
fail();
- } catch (InterruptedException e) {
- fail();
} catch (Exception e) {
fail();
}
@@ -548,7 +496,7 @@ public void handleLogbook3ChangeState() {
* Test {@link org.phoebus.olog.OlogResourceDescriptors#LOGBOOK_RESOURCE_URI}.
*/
@Test
- public void handleLogbooksCreateCheck() {
+ void handleLogbooksCreateCheck() {
// what
// check(s) for create logbooks
// e.g.
@@ -566,58 +514,46 @@ public void handleLogbooksCreateCheck() {
// Remove Logbook
Logbook logbook_check = new Logbook();
+ Logbook[] logbooks = new Logbook[] {
+ logbook_l1_owner_a_state_a,
+ logbook_l2_owner_a_state_a,
+ logbook_l3_owner_a_state_a,
+ logbook_l4_owner_a_state_a,
+ logbook_l5_owner_a_state_a,
+ logbook_l6_owner_a_state_i,
+ logbook_l7_owner_a_state_i,
+ logbook_l8_owner_a_state_i,
+ logbook_l9_owner_a_state_i,
+ logbook_l10_owner_a_state_i,
+ logbook_check
+ };
- ObjectMapper mapper = new ObjectMapper();
-
- try {
- String[] response = ITUtil.doGetJson(HTTP_IP_PORT_OLOG_LOGBOOKS);
- ITUtil.assertResponseLength2CodeOKContent(response, ITUtil.EMPTY_JSON);
-
- Logbook[] logbooks = new Logbook[] {
- logbook_l1_owner_a_state_a,
- logbook_l2_owner_a_state_a,
- logbook_l3_owner_a_state_a,
- logbook_l4_owner_a_state_a,
- logbook_l5_owner_a_state_a,
- logbook_l6_owner_a_state_i,
- logbook_l7_owner_a_state_i,
- logbook_l8_owner_a_state_i,
- logbook_l9_owner_a_state_i,
- logbook_l10_owner_a_state_i,
- logbook_check
- };
+ ITUtilLogbooks.assertListLogbooks(2,
+ default_logbooks[1],
+ default_logbooks[0]);
- response = ITUtil.runShellCommand(createCurlLogbooksForAdmin(mapper.writeValueAsString(logbooks)));
- ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_BAD_REQUEST);
+ ITUtilLogbooks.assertCreateLogbooks("", logbooks, HttpURLConnection.HTTP_BAD_REQUEST);
- logbook_check.setName(null);
- logbooks[10] = logbook_check;
+ logbook_check.setName(null);
+ logbooks[10] = logbook_check;
- response = ITUtil.runShellCommand(createCurlLogbooksForAdmin(mapper.writeValueAsString(logbooks)));
- ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_BAD_REQUEST);
+ ITUtilLogbooks.assertCreateLogbooks("", logbooks, HttpURLConnection.HTTP_BAD_REQUEST);
- logbook_check.setName("");
- logbooks[10] = logbook_check;
+ logbook_check.setName("");
+ logbooks[10] = logbook_check;
- response = ITUtil.runShellCommand(createCurlLogbooksForAdmin(mapper.writeValueAsString(logbooks)));
- ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_BAD_REQUEST);
+ ITUtilLogbooks.assertCreateLogbooks("", logbooks, HttpURLConnection.HTTP_BAD_REQUEST);
- response = ITUtil.doGetJson(HTTP_IP_PORT_OLOG_LOGBOOKS);
- ITUtil.assertResponseLength2CodeOKContent(response, ITUtil.EMPTY_JSON);
- } catch (IOException e) {
- fail();
- } catch (InterruptedException e) {
- fail();
- } catch (Exception e) {
- fail();
- }
+ ITUtilLogbooks.assertListLogbooks(2,
+ default_logbooks[1],
+ default_logbooks[0]);
}
/**
* Test {@link org.phoebus.olog.OlogResourceDescriptors#LOGBOOK_RESOURCE_URI}.
*/
@Test
- public void handleLogbooks() {
+ void handleLogbooks() {
// what
// create logbooks
// --------------------------------------------------------------------------------
@@ -642,170 +578,68 @@ public void handleLogbooks() {
logbook_l10_owner_a_state_i
};
- ObjectMapper mapper = new ObjectMapper();
-
try {
- String[] response = ITUtil.doGetJson(HTTP_IP_PORT_OLOG_LOGBOOKS);
- ITUtil.assertResponseLength2CodeOKContent(response, ITUtil.EMPTY_JSON);
+ ITUtilLogbooks.assertListLogbooks(2,
+ default_logbooks[1],
+ default_logbooks[0]);
- response = ITUtil.runShellCommand(createCurlLogbooksForAdmin(mapper.writeValueAsString(logbooks_active_inactive)));
- ITUtil.assertResponseLength2CodeOK(response);
- ITUtil.assertEqualsLogbooks(
- mapper.readValue(response[1], Logbook[].class),
- logbooks_active_inactive);
+ ITUtilLogbooks.assertCreateLogbooks("", logbooks_active_inactive);
// refresh elastic indices
- response = ITUtil.refreshElasticIndices();
- ITUtil.assertResponseLength2CodeOK(response);
+ ITUtil.assertRefreshElasticIndices();
- response = ITUtil.doGetJson(HTTP_IP_PORT_OLOG_LOGBOOKS);
- ITUtil.assertResponseLength2CodeOK(response);
- ITUtil.assertEqualsLogbooks(
- mapper.readValue(response[1], Logbook[].class),
+ ITUtilLogbooks.assertListLogbooks(7,
+ default_logbooks[1],
logbook_l1_owner_a_state_a,
logbook_l2_owner_a_state_a,
logbook_l3_owner_a_state_a,
logbook_l4_owner_a_state_a,
- logbook_l5_owner_a_state_a);
-
- response = ITUtil.doGetJson(HTTP_IP_PORT_OLOG_LOGBOOKS + "/l1");
- ITUtil.assertResponseLength2CodeOK(response);
- assertEquals(logbook_l1_owner_a_state_a, mapper.readValue(response[1], Logbook.class));
-
- response = ITUtil.doGetJson(HTTP_IP_PORT_OLOG_LOGBOOKS + "/l2");
- ITUtil.assertResponseLength2CodeOK(response);
- assertEquals(logbook_l2_owner_a_state_a, mapper.readValue(response[1], Logbook.class));
-
- response = ITUtil.doGetJson(HTTP_IP_PORT_OLOG_LOGBOOKS + "/l3");
- ITUtil.assertResponseLength2CodeOK(response);
- assertEquals(logbook_l3_owner_a_state_a, mapper.readValue(response[1], Logbook.class));
-
- response = ITUtil.doGetJson(HTTP_IP_PORT_OLOG_LOGBOOKS + "/l4");
- ITUtil.assertResponseLength2CodeOK(response);
- assertEquals(logbook_l4_owner_a_state_a, mapper.readValue(response[1], Logbook.class));
-
- response = ITUtil.doGetJson(HTTP_IP_PORT_OLOG_LOGBOOKS + "/l5");
- ITUtil.assertResponseLength2CodeOK(response);
- assertEquals(logbook_l5_owner_a_state_a, mapper.readValue(response[1], Logbook.class));
-
- response = ITUtil.doGetJson(HTTP_IP_PORT_OLOG_LOGBOOKS + "/l6");
- ITUtil.assertResponseLength2CodeOK(response);
- assertEquals(logbook_l6_owner_a_state_i, mapper.readValue(response[1], Logbook.class));
-
- response = ITUtil.doGetJson(HTTP_IP_PORT_OLOG_LOGBOOKS + "/l7");
- ITUtil.assertResponseLength2CodeOK(response);
- assertEquals(logbook_l7_owner_a_state_i, mapper.readValue(response[1], Logbook.class));
-
- response = ITUtil.doGetJson(HTTP_IP_PORT_OLOG_LOGBOOKS + "/l8");
- ITUtil.assertResponseLength2CodeOK(response);
- assertEquals(logbook_l8_owner_a_state_i, mapper.readValue(response[1], Logbook.class));
-
- response = ITUtil.doGetJson(HTTP_IP_PORT_OLOG_LOGBOOKS + "/l9");
- ITUtil.assertResponseLength2CodeOK(response);
- assertEquals(logbook_l9_owner_a_state_i, mapper.readValue(response[1], Logbook.class));
-
- response = ITUtil.doGetJson(HTTP_IP_PORT_OLOG_LOGBOOKS + "/l10");
- ITUtil.assertResponseLength2CodeOK(response);
- assertEquals(logbook_l10_owner_a_state_i, mapper.readValue(response[1], Logbook.class));
-
- response = ITUtil.runShellCommand(deleteCurlLogbookForAdmin("l1"));
- ITUtil.assertResponseLength2CodeOK(response);
-
- response = ITUtil.runShellCommand(deleteCurlLogbookForAdmin("l2"));
- ITUtil.assertResponseLength2CodeOK(response);
-
- response = ITUtil.runShellCommand(deleteCurlLogbookForAdmin("l3"));
- ITUtil.assertResponseLength2CodeOK(response);
-
- response = ITUtil.runShellCommand(deleteCurlLogbookForAdmin("l9"));
- ITUtil.assertResponseLength2CodeOK(response);
+ logbook_l5_owner_a_state_a,
+ default_logbooks[0]);
+
+ ITUtilLogbooks.assertRetrieveLogbook("/l1", logbook_l1_owner_a_state_a);
+ ITUtilLogbooks.assertRetrieveLogbook("/l2", logbook_l2_owner_a_state_a);
+ ITUtilLogbooks.assertRetrieveLogbook("/l3", logbook_l3_owner_a_state_a);
+ ITUtilLogbooks.assertRetrieveLogbook("/l4", logbook_l4_owner_a_state_a);
+ ITUtilLogbooks.assertRetrieveLogbook("/l5", logbook_l5_owner_a_state_a);
+ ITUtilLogbooks.assertRetrieveLogbook("/l6", logbook_l6_owner_a_state_i);
+ ITUtilLogbooks.assertRetrieveLogbook("/l7", logbook_l7_owner_a_state_i);
+ ITUtilLogbooks.assertRetrieveLogbook("/l8", logbook_l8_owner_a_state_i);
+ ITUtilLogbooks.assertRetrieveLogbook("/l9", logbook_l9_owner_a_state_i);
+ ITUtilLogbooks.assertRetrieveLogbook("/l10", logbook_l10_owner_a_state_i);
+
+ ITUtilLogbooks.assertRemoveLogbook("/l1");
+ ITUtilLogbooks.assertRemoveLogbook("/l2");
+ ITUtilLogbooks.assertRemoveLogbook("/l3");
+ ITUtilLogbooks.assertRemoveLogbook("/l9");
+ ITUtilLogbooks.assertRemoveLogbook("/l10");
- response = ITUtil.runShellCommand(deleteCurlLogbookForAdmin("l10"));
- ITUtil.assertResponseLength2CodeOK(response);
+ // refresh elastic indices
+ ITUtil.assertRefreshElasticIndices();
- response = ITUtil.doGetJson(HTTP_IP_PORT_OLOG_LOGBOOKS);
- ITUtil.assertResponseLength2CodeOK(response);
- ITUtil.assertEqualsLogbooks(
- mapper.readValue(response[1], Logbook[].class),
+ ITUtilLogbooks.assertListLogbooks(4,
+ default_logbooks[1],
logbook_l4_owner_a_state_a,
- logbook_l5_owner_a_state_a);
-
- response = ITUtil.runShellCommand(deleteCurlLogbookForAdmin("l4"));
- ITUtil.assertResponseLength2CodeOK(response);
-
- response = ITUtil.runShellCommand(deleteCurlLogbookForAdmin("l5"));
- ITUtil.assertResponseLength2CodeOK(response);
-
- response = ITUtil.runShellCommand(deleteCurlLogbookForAdmin("l6"));
- ITUtil.assertResponseLength2CodeOK(response);
+ logbook_l5_owner_a_state_a,
+ default_logbooks[0]);
- response = ITUtil.runShellCommand(deleteCurlLogbookForAdmin("l7"));
- ITUtil.assertResponseLength2CodeOK(response);
+ ITUtilLogbooks.assertRemoveLogbook("/l4");
+ ITUtilLogbooks.assertRemoveLogbook("/l5");
+ ITUtilLogbooks.assertRemoveLogbook("/l6");
+ ITUtilLogbooks.assertRemoveLogbook("/l7");
+ ITUtilLogbooks.assertRemoveLogbook("/l8");
- response = ITUtil.runShellCommand(deleteCurlLogbookForAdmin("l8"));
- ITUtil.assertResponseLength2CodeOK(response);
+ // refresh elastic indices
+ ITUtil.assertRefreshElasticIndices();
- response = ITUtil.doGetJson(HTTP_IP_PORT_OLOG_LOGBOOKS);
- ITUtil.assertResponseLength2CodeOK(response);
+ ITUtilLogbooks.assertListLogbooks(2,
+ default_logbooks[1],
+ default_logbooks[0]);
} catch (IOException e) {
fail();
- } catch (InterruptedException e) {
- fail();
} catch (Exception e) {
fail();
}
}
- /**
- * Utility method to return curl to create logbook for regular user.
- *
- * @param logbookName logbook name
- * @param logbookJson logbook json
- * @return curl to create logbook
- */
- private static String createCurlLogbookForUser(String logbookName, String logbookJson) {
- return "curl -H " + ITUtil.HEADER_JSON + " -XPUT -i " + OlogLogbooksIT.HTTP_AUTH_USER_IP_PORT_OLOG_LOGBOOKS + "/" + logbookName + " -d '" + logbookJson + "'";
- }
-
- /**
- * Utility method to return curl to create logbook for admin user.
- *
- * @param logbookName logbook name
- * @param logbookJson logbook json
- * @return curl to create logbook
- */
- private static String createCurlLogbookForAdmin(String logbookName, String logbookJson) {
- return "curl -H " + ITUtil.HEADER_JSON + " -XPUT -i " + OlogLogbooksIT.HTTP_AUTH_ADMIN_IP_PORT_OLOG_LOGBOOKS + "/" + logbookName + " -d '" + logbookJson + "'";
- }
-
- /**
- * Utility method to return curl to create logbooks for admin user.
- *
- * @param logbooksJson logbooks json
- * @return curl to create logbooks
- */
- private static String createCurlLogbooksForAdmin(String logbooksJson) {
- return "curl -H " + ITUtil.HEADER_JSON + " -XPUT -i " + HTTP_AUTH_ADMIN_IP_PORT_OLOG_LOGBOOKS + " -d '" + logbooksJson + "'";
- }
-
- /**
- * Utility method to return curl to delete logbook for regular user.
- *
- * @param logbookName logbook name
- * @return curl to delete logbook
- */
- private static String deleteCurlLogbookForUser(String logbookName) {
- return "curl -H " + ITUtil.HEADER_JSON + " -XDELETE -i " + HTTP_AUTH_USER_IP_PORT_OLOG_LOGBOOKS + "/" + logbookName;
- }
-
- /**
- * Utility method to return curl to delete logbook for admin user.
- *
- * @param logbookName logbook name
- * @return curl to delete logbook
- */
- private static String deleteCurlLogbookForAdmin(String logbookName) {
- return "curl -H " + ITUtil.HEADER_JSON + " -XDELETE -i " + HTTP_AUTH_ADMIN_IP_PORT_OLOG_LOGBOOKS + "/" + logbookName;
- }
-
}
diff --git a/src/test/java/org/phoebus/olog/docker/OlogLogsIT.java b/src/test/java/org/phoebus/olog/docker/OlogLogsIT.java
index 42750e2..3111ab8 100644
--- a/src/test/java/org/phoebus/olog/docker/OlogLogsIT.java
+++ b/src/test/java/org/phoebus/olog/docker/OlogLogsIT.java
@@ -1,18 +1,31 @@
/*
* Copyright (C) 2021 European Spallation Source ERIC.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
package org.phoebus.olog.docker;
-import com.fasterxml.jackson.databind.ObjectMapper;
+import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Test;
+import org.phoebus.olog.docker.ITUtil.AuthorizationChoice;
import org.phoebus.olog.entity.Log;
-import org.testcontainers.containers.DockerComposeContainer;
-import org.testcontainers.containers.wait.strategy.Wait;
+import org.testcontainers.containers.ComposeContainer;
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;
-import java.io.File;
import java.io.IOException;
import java.net.HttpURLConnection;
@@ -32,7 +45,7 @@
* @see org.phoebus.olog.LogResource
*/
@Testcontainers
-public class OlogLogsIT {
+class OlogLogsIT {
// Note
// ------------------------------------------------------------------------------------------------
@@ -53,32 +66,31 @@ public class OlogLogsIT {
// Olog - Service Documentation
// https://olog.readthedocs.io/en/latest/
// ------------------------------------------------------------------------------------------------
- // OLOG API LogbooksResource
- // -------------------- --------------------
- // Retrieve a Log .../logs/ (GET) getLog(String)
- // Retrieve attachment for Log .../logs/attachments/{logId}/{attachmentName}
- // (GET) findResources(String, String)
- // List Logs / Query by Pattern .../logs (GET) findAll()
- // Create a Log .../logs (PUT) createLog(String, Log, Principal)
- // Upload attachment .../logs/attachments/{logId}
- // (POST) uploadAttachment(String, MultipartFile, String, String, String)
- // Upload multiple attachments .../logs/attachments-multi/{logId}
- // (POST) uploadMultipleAttachments(String, MultipartFile[])
+ // OLOG API LogbooksResource
+ // -------------------- --------------------
+ // Retrieve a Log .../logs/ (GET) getLog(String)
+ // Retrieve attachment for Log .../logs/attachments/{logId}/{attachmentName}
+ // (GET) findResources(String, String)
+ // List Logs / Query by Pattern .../logs (GET) findAll()
+ // Create a Log .../logs (PUT) createLog(String, Log, Principal)
+ // Upload attachment .../logs/attachments/{logId}
+ // (POST) uploadAttachment(String, MultipartFile, String, String, String)
+ // Upload multiple attachments .../logs/attachments-multi/{logId}
+ // (POST) uploadMultipleAttachments(String, MultipartFile[])
// ------------------------------------------------------------------------------------------------
- static final String LOGS = "/logs";
-
- static final String HTTP_IP_PORT_OLOG_LOGS = ITUtil.HTTP + ITUtil.IP_PORT_OLOG + LOGS;
- static final String HTTP_AUTH_USER_IP_PORT_OLOG_LOGS = ITUtil.HTTP + ITUtil.AUTH_USER + "@" + ITUtil.IP_PORT_OLOG + LOGS;
- static final String HTTP_AUTH_ADMIN_IP_PORT_OLOG_LOGS = ITUtil.HTTP + ITUtil.AUTH_ADMIN + "@" + ITUtil.IP_PORT_OLOG + LOGS;
-
@Container
- public static final DockerComposeContainer> ENVIRONMENT =
- new DockerComposeContainer<>(new File("docker-compose.yml"))
- .waitingFor(ITUtil.OLOG, Wait.forLogMessage(".*Started Application.*", 1));
+ public static final ComposeContainer ENVIRONMENT = ITUtil.defaultComposeContainers();
+
+ @AfterAll
+ public static void extractJacocoReport() {
+ // extract jacoco report from container file system
+ ITUtil.extractJacocoReport(ENVIRONMENT,
+ ITUtil.JACOCO_TARGET_PREFIX + OlogLogsIT.class.getSimpleName() + ITUtil.JACOCO_TARGET_SUFFIX);
+ }
@Test
- public void ologUp() {
+ void ologUp() {
try {
String address = ITUtil.HTTP_IP_PORT_OLOG;
int responseCode = ITUtil.doGet(address);
@@ -93,7 +105,7 @@ public void ologUp() {
* Test {@link org.phoebus.olog.OlogResourceDescriptors#LOG_RESOURCE_URI}.
*/
@Test
- public void handleLogRetrieveCheck() {
+ void handleLogRetrieveCheck() {
// what
// check(s) for retrieve log
// e.g.
@@ -106,19 +118,14 @@ public void handleLogRetrieveCheck() {
// Upload attachment
// Upload multiple attachments
- try {
- String[] response = ITUtil.doGetJson(HTTP_IP_PORT_OLOG_LOGS + "/l11");
- ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_NOT_FOUND);
- } catch (IOException e) {
- fail();
- }
+ ITUtilTags.assertRetrieveTag("/l11", HttpURLConnection.HTTP_NOT_FOUND);
}
/**
* Test {@link org.phoebus.olog.OlogResourceDescriptors#LOG_RESOURCE_URI}.
*/
@Test
- public void handleLogCreateCheckJson() {
+ void handleLogCreateCheckJson() {
// what
// check(s) for create log
// e.g.
@@ -146,53 +153,26 @@ public void handleLogCreateCheckJson() {
String json_incomplete8 = "}";
String json_incomplete9 = "\"";
- try {
- String[] response = ITUtil.doGetJson(HTTP_IP_PORT_OLOG_LOGS);
- ITUtil.assertResponseLength2CodeOKContent(response, ITUtil.EMPTY_JSON);
-
- response = ITUtil.runShellCommand(createCurlLogForAdmin(json_incomplete1));
- ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_BAD_REQUEST);
-
- response = ITUtil.runShellCommand(createCurlLogForAdmin(json_incomplete2));
- ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_BAD_REQUEST);
-
- response = ITUtil.runShellCommand(createCurlLogForAdmin(json_incomplete3));
- ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_BAD_REQUEST);
-
- response = ITUtil.runShellCommand(createCurlLogForAdmin(json_incomplete4));
- ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_BAD_REQUEST);
+ ITUtilLogs.assertListLogs(0);
- response = ITUtil.runShellCommand(createCurlLogForAdmin(json_incomplete5));
- ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_BAD_REQUEST);
+ ITUtilLogs.assertCreateLog(AuthorizationChoice.ADMIN, "", json_incomplete1, HttpURLConnection.HTTP_BAD_REQUEST);
+ ITUtilLogs.assertCreateLog(AuthorizationChoice.ADMIN, "", json_incomplete2, HttpURLConnection.HTTP_BAD_REQUEST);
+ ITUtilLogs.assertCreateLog(AuthorizationChoice.ADMIN, "", json_incomplete3, HttpURLConnection.HTTP_BAD_REQUEST);
+ ITUtilLogs.assertCreateLog(AuthorizationChoice.ADMIN, "", json_incomplete4, HttpURLConnection.HTTP_BAD_REQUEST);
+ ITUtilLogs.assertCreateLog(AuthorizationChoice.ADMIN, "", json_incomplete5, HttpURLConnection.HTTP_BAD_REQUEST);
+ ITUtilLogs.assertCreateLog(AuthorizationChoice.ADMIN, "", json_incomplete6, HttpURLConnection.HTTP_BAD_REQUEST);
+ ITUtilLogs.assertCreateLog(AuthorizationChoice.ADMIN, "", json_incomplete7, HttpURLConnection.HTTP_BAD_REQUEST);
+ ITUtilLogs.assertCreateLog(AuthorizationChoice.ADMIN, "", json_incomplete8, HttpURLConnection.HTTP_BAD_REQUEST);
+ ITUtilLogs.assertCreateLog(AuthorizationChoice.ADMIN, "", json_incomplete9, HttpURLConnection.HTTP_BAD_REQUEST);
- response = ITUtil.runShellCommand(createCurlLogForAdmin(json_incomplete6));
- ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_BAD_REQUEST);
-
- response = ITUtil.runShellCommand(createCurlLogForAdmin(json_incomplete7));
- ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_BAD_REQUEST);
-
- response = ITUtil.runShellCommand(createCurlLogForAdmin(json_incomplete8));
- ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_BAD_REQUEST);
-
- response = ITUtil.runShellCommand(createCurlLogForAdmin(json_incomplete9));
- ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_BAD_REQUEST);
-
- response = ITUtil.doGetJson(HTTP_IP_PORT_OLOG_LOGS);
- ITUtil.assertResponseLength2CodeOKContent(response, ITUtil.EMPTY_JSON);
- } catch (IOException e) {
- fail();
- } catch (InterruptedException e) {
- fail();
- } catch (Exception e) {
- fail();
- }
+ ITUtilLogs.assertListLogs(0);
}
/**
* Test {@link org.phoebus.olog.OlogResourceDescriptors#LOG_RESOURCE_URI}.
*/
@Test
- public void handleLogCreateCheck() {
+ void handleLogCreateCheck() {
// what
// check(s) for create log
// e.g.
@@ -210,49 +190,14 @@ public void handleLogCreateCheck() {
// Upload attachment
// Upload multiple attachments
- Log log_check = new Log.LogBuilder().build();
-
- ObjectMapper mapper = new ObjectMapper();
+ Log log_check = new Log.LogBuilder().build();
- try {
- String[] response = ITUtil.doGetJson(HTTP_IP_PORT_OLOG_LOGS);
- ITUtil.assertResponseLength2CodeOKContent(response, ITUtil.EMPTY_JSON);
-
- response = ITUtil.runShellCommand(createCurlLogForUser(mapper.writeValueAsString(log_check)));
- ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_BAD_REQUEST);
-
- response = ITUtil.runShellCommand(createCurlLogForAdmin(mapper.writeValueAsString(log_check)));
- ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_BAD_REQUEST);
-
- response = ITUtil.doGetJson(HTTP_IP_PORT_OLOG_LOGS);
- ITUtil.assertResponseLength2CodeOKContent(response, ITUtil.EMPTY_JSON);
- } catch (IOException e) {
- fail();
- } catch (InterruptedException e) {
- fail();
- } catch (Exception e) {
- fail();
- }
- }
+ ITUtilLogs.assertListLogs(0);
- /**
- * Utility method to return curl to create log for regular user.
- *
- * @param logJson log json
- * @return curl to create log
- */
- private static String createCurlLogForUser(String logJson) {
- return "curl -H " + ITUtil.HEADER_JSON + " -XPUT -i " + HTTP_AUTH_USER_IP_PORT_OLOG_LOGS + " -d '" + logJson + "'";
- }
+ ITUtilLogs.assertCreateLog(AuthorizationChoice.ADMIN, "", log_check, HttpURLConnection.HTTP_BAD_REQUEST);
+ ITUtilLogs.assertCreateLog(AuthorizationChoice.ADMIN, "", log_check, HttpURLConnection.HTTP_BAD_REQUEST);
- /**
- * Utility method to return curl to create log for admin user.
- *
- * @param logJson log json
- * @return curl to create log
- */
- private static String createCurlLogForAdmin(String logJson) {
- return "curl -H " + ITUtil.HEADER_JSON + " -XPUT -i " + HTTP_AUTH_ADMIN_IP_PORT_OLOG_LOGS + " -d '" + logJson + "'";
+ ITUtilLogs.assertListLogs(0);
}
}
diff --git a/src/test/java/org/phoebus/olog/docker/OlogLogsQueryIT.java b/src/test/java/org/phoebus/olog/docker/OlogLogsQueryIT.java
index ccaed5d..846baf9 100644
--- a/src/test/java/org/phoebus/olog/docker/OlogLogsQueryIT.java
+++ b/src/test/java/org/phoebus/olog/docker/OlogLogsQueryIT.java
@@ -1,25 +1,36 @@
/*
* Copyright (C) 2021 European Spallation Source ERIC.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
package org.phoebus.olog.docker;
-import com.fasterxml.jackson.databind.ObjectMapper;
+import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Test;
-import org.phoebus.olog.entity.Log;
-import org.testcontainers.containers.DockerComposeContainer;
-import org.testcontainers.containers.wait.strategy.Wait;
+import org.phoebus.olog.entity.SearchResult;
+import org.testcontainers.containers.ComposeContainer;
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;
-import java.io.File;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.fail;
/**
@@ -35,7 +46,7 @@
* @see org.phoebus.olog.LogResource
*/
@Testcontainers
-public class OlogLogsQueryIT {
+class OlogLogsQueryIT {
// Note
// ------------------------------------------------------------------------------------------------
@@ -57,32 +68,31 @@ public class OlogLogsQueryIT {
// Olog - Service Documentation
// https://olog.readthedocs.io/en/latest/
// ------------------------------------------------------------------------------------------------
- // OLOG API LogbooksResource
- // -------------------- --------------------
- // Retrieve a Log .../logs/ (GET) getLog(String)
- // Retrieve attachment for Log .../logs/attachments/{logId}/{attachmentName}
- // (GET) findResources(String, String)
- // List Logs / Query by Pattern .../logs (GET) findAll()
- // Create a Log .../logs (PUT) createLog(String, Log, Principal)
- // Upload attachment .../logs/attachments/{logId}
- // (POST) uploadAttachment(String, MultipartFile, String, String, String)
- // Upload multiple attachments .../logs/attachments-multi/{logId}
- // (POST) uploadMultipleAttachments(String, MultipartFile[])
+ // OLOG API LogbooksResource
+ // -------------------- --------------------
+ // Retrieve a Log .../logs/ (GET) getLog(String)
+ // Retrieve attachment for Log .../logs/attachments/{logId}/{attachmentName}
+ // (GET) findResources(String, String)
+ // List Logs / Query by Pattern .../logs (GET) findAll()
+ // Create a Log .../logs (PUT) createLog(String, Log, Principal)
+ // Upload attachment .../logs/attachments/{logId}
+ // (POST) uploadAttachment(String, MultipartFile, String, String, String)
+ // Upload multiple attachments .../logs/attachments-multi/{logId}
+ // (POST) uploadMultipleAttachments(String, MultipartFile[])
// ------------------------------------------------------------------------------------------------
- static final String LOGS = "/logs";
-
- static final String HTTP_IP_PORT_OLOG_LOGS = ITUtil.HTTP + ITUtil.IP_PORT_OLOG + LOGS;
- static final String HTTP_AUTH_USER_IP_PORT_OLOG_LOGS = ITUtil.HTTP + ITUtil.AUTH_USER + "@" + ITUtil.IP_PORT_OLOG + LOGS;
- static final String HTTP_AUTH_ADMIN_IP_PORT_OLOG_LOGS = ITUtil.HTTP + ITUtil.AUTH_ADMIN + "@" + ITUtil.IP_PORT_OLOG + LOGS;
-
@Container
- public static final DockerComposeContainer> ENVIRONMENT =
- new DockerComposeContainer<>(new File("docker-compose.yml"))
- .waitingFor(ITUtil.OLOG, Wait.forLogMessage(".*Started Application.*", 1));
+ public static final ComposeContainer ENVIRONMENT = ITUtil.defaultComposeContainers();
+
+ @AfterAll
+ public static void extractJacocoReport() {
+ // extract jacoco report from container file system
+ ITUtil.extractJacocoReport(ENVIRONMENT,
+ ITUtil.JACOCO_TARGET_PREFIX + OlogLogsQueryIT.class.getSimpleName() + ITUtil.JACOCO_TARGET_SUFFIX);
+ }
@Test
- public void ologUp() {
+ void ologUp() {
try {
String address = ITUtil.HTTP_IP_PORT_OLOG;
int responseCode = ITUtil.doGet(address);
@@ -97,13 +107,16 @@ public void ologUp() {
* Test {@link org.phoebus.olog.OlogResourceDescriptors#LOG_RESOURCE_URI}.
*/
@Test
- public void handleLogsQueryByPattern() {
+ void handleLogsQueryByPattern() {
// what
// query by pattern
// --------------------------------------------------------------------------------
// set up test fixture
// test
// query by pattern
+ // url
+ // Olog/logs
+ // Olog/logs/search
// combine search parameters and logs (logbooks, tags, properties, attachments)
// tear down test fixture
@@ -118,25 +131,26 @@ public void handleLogsQueryByPattern() {
// --------------------------------------------------------------------------------
// search parameters
// keyword
- // text
- // owner
- // desc
- // description
- // title
- // level
- // phrase (description)
- // fuzzy (?)
- // meta data
- // logbooks
- // tags
- // properties
- // time
- // start (createdDate)
- // end (createdDate)
- // includeevent (with start, end)
- // includeevents (with start, end)
- // default
- // unsupported search parameters are ignored
+ // desc, description, text
+ // title
+ // fuzzy
+ // phrase
+ // owner
+ // tags
+ // logbooks
+ // start
+ // end
+ // includeevents, includeevent
+ // properties
+ // level
+ // size, limit
+ // from
+ // sort
+ // attachments
+ // keyword combinations
+ // --------------------------------------------------------------------------------
+ // default
+ // unsupported search parameters are ignored
// --------------------------------------------------------------------------------
// query for pattern
// existing
@@ -150,793 +164,564 @@ public void handleLogsQueryByPattern() {
// non-existing
// --------------------------------------------------------------------------------
- ObjectMapper mapper = new ObjectMapper();
+ SearchResult searchResult = null;
try {
- String[] response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS);
- ITUtil.assertResponseLength2CodeOK(response);
- Log[] logs = mapper.readValue(response[1], Log[].class);
- assertNotNull(logs);
- assertEquals(60, logs.length);
+ ITUtilLogs.assertListLogs(60);
+ // ----------------------------------------------------------------------------------------------------
// keyword
- // text
- // owner
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?owner");
- ITUtil.assertResponseLength2CodeOKContent(response, ITUtil.EMPTY_JSON);
-
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?owner=asdf");
- ITUtil.assertResponseLength2CodeOKContent(response, ITUtil.EMPTY_JSON);
-
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?owner=admin");
- ITUtil.assertResponseLength2CodeOK(response);
- logs = mapper.readValue(response[1], Log[].class);
- assertNotNull(logs);
- assertEquals(60, logs.length);
-
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?owner=adm?n");
- ITUtil.assertResponseLength2CodeOK(response);
- logs = mapper.readValue(response[1], Log[].class);
- assertNotNull(logs);
- assertEquals(60, logs.length);
-
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?owner=adm?m");
- ITUtil.assertResponseLength2CodeOKContent(response, ITUtil.EMPTY_JSON);
-
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?owner=adm*");
- ITUtil.assertResponseLength2CodeOK(response);
- logs = mapper.readValue(response[1], Log[].class);
- assertNotNull(logs);
- assertEquals(60, logs.length);
-
- // desc
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?desc");
- ITUtil.assertResponseLength2CodeOKContent(response, ITUtil.EMPTY_JSON);
-
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?desc=asdf");
- ITUtil.assertResponseLength2CodeOKContent(response, ITUtil.EMPTY_JSON);
-
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?desc=Initial");
- ITUtil.assertResponseLength2CodeOKContent(response, ITUtil.EMPTY_JSON);
-
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?desc=check");
- ITUtil.assertResponseLength2CodeOK(response);
- logs = mapper.readValue(response[1], Log[].class);
- assertNotNull(logs);
- assertEquals(8, logs.length);
-
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?desc=Check");
- ITUtil.assertResponseLength2CodeOK(response);
- logs = mapper.readValue(response[1], Log[].class);
- assertNotNull(logs);
- assertEquals(8, logs.length);
-
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?desc=complete");
- ITUtil.assertResponseLength2CodeOK(response);
- logs = mapper.readValue(response[1], Log[].class);
- assertNotNull(logs);
- assertEquals(4, logs.length);
-
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?desc=Complete");
- ITUtil.assertResponseLength2CodeOK(response);
- logs = mapper.readValue(response[1], Log[].class);
- assertNotNull(logs);
- assertEquals(4, logs.length);
-
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?desc=check complete");
- ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_VERSION);
-
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?desc='check complete'");
- ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_VERSION);
-
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?desc=check&desc=complete");
- ITUtil.assertResponseLength2CodeOK(response);
- logs = mapper.readValue(response[1], Log[].class);
- assertNotNull(logs);
- assertEquals(10, logs.length);
-
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?desc="+URLEncoder.encode("check complete", StandardCharsets.UTF_8));
- ITUtil.assertResponseLength2CodeOK(response);
- logs = mapper.readValue(response[1], Log[].class);
- assertNotNull(logs);
- assertEquals(10, logs.length);
-
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?desc='"+URLEncoder.encode("check complete", StandardCharsets.UTF_8)+"'");
- ITUtil.assertResponseLength2CodeOKContent(response, ITUtil.EMPTY_JSON);
-
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?desc="+URLEncoder.encode("CHECK COMPLETE", StandardCharsets.UTF_8));
- ITUtil.assertResponseLength2CodeOK(response);
- logs = mapper.readValue(response[1], Log[].class);
- assertNotNull(logs);
- assertEquals(10, logs.length);
-
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?desc='"+URLEncoder.encode("CHECK COMPLETE", StandardCharsets.UTF_8)+"'");
- ITUtil.assertResponseLength2CodeOKContent(response, ITUtil.EMPTY_JSON);
-
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?desc=chec?");
- ITUtil.assertResponseLength2CodeOK(response);
- logs = mapper.readValue(response[1], Log[].class);
- assertNotNull(logs);
- assertEquals(8, logs.length);
-
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?desc=?omplete");
- ITUtil.assertResponseLength2CodeOK(response);
- logs = mapper.readValue(response[1], Log[].class);
- assertNotNull(logs);
- assertEquals(4, logs.length);
-
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?desc=c*");
- ITUtil.assertResponseLength2CodeOK(response);
- logs = mapper.readValue(response[1], Log[].class);
- assertNotNull(logs);
- assertEquals(18, logs.length);
-
- // description
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?description");
- ITUtil.assertResponseLength2CodeOKContent(response, ITUtil.EMPTY_JSON);
-
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?description=asdf");
- ITUtil.assertResponseLength2CodeOKContent(response, ITUtil.EMPTY_JSON);
-
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?description=Initial");
- ITUtil.assertResponseLength2CodeOKContent(response, ITUtil.EMPTY_JSON);
-
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?description=check");
- ITUtil.assertResponseLength2CodeOK(response);
- logs = mapper.readValue(response[1], Log[].class);
- assertNotNull(logs);
- assertEquals(8, logs.length);
-
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?description=Check");
- ITUtil.assertResponseLength2CodeOK(response);
- logs = mapper.readValue(response[1], Log[].class);
- assertNotNull(logs);
- assertEquals(8, logs.length);
-
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?description=complete");
- ITUtil.assertResponseLength2CodeOK(response);
- logs = mapper.readValue(response[1], Log[].class);
- assertNotNull(logs);
- assertEquals(4, logs.length);
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?description=Complete");
- ITUtil.assertResponseLength2CodeOK(response);
- logs = mapper.readValue(response[1], Log[].class);
- assertNotNull(logs);
- assertEquals(4, logs.length);
-
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?description=check complete");
- ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_VERSION);
-
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?description='check complete'");
- ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_VERSION);
-
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?description=check&desc=complete");
- ITUtil.assertResponseLength2CodeOK(response);
- logs = mapper.readValue(response[1], Log[].class);
- assertNotNull(logs);
- assertEquals(10, logs.length);
-
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?description="+URLEncoder.encode("check complete", StandardCharsets.UTF_8));
- ITUtil.assertResponseLength2CodeOK(response);
- logs = mapper.readValue(response[1], Log[].class);
- assertNotNull(logs);
- assertEquals(10, logs.length);
-
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?description='"+URLEncoder.encode("check complete", StandardCharsets.UTF_8)+"'");
- ITUtil.assertResponseLength2CodeOKContent(response, ITUtil.EMPTY_JSON);
-
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?description="+URLEncoder.encode("CHECK COMPLETE", StandardCharsets.UTF_8));
- ITUtil.assertResponseLength2CodeOK(response);
- logs = mapper.readValue(response[1], Log[].class);
- assertNotNull(logs);
- assertEquals(10, logs.length);
-
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?description='"+URLEncoder.encode("CHECK COMPLETE", StandardCharsets.UTF_8)+"'");
- ITUtil.assertResponseLength2CodeOKContent(response, ITUtil.EMPTY_JSON);
-
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?description=chec?");
- ITUtil.assertResponseLength2CodeOK(response);
- logs = mapper.readValue(response[1], Log[].class);
- assertNotNull(logs);
- assertEquals(8, logs.length);
-
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?description=?omplete");
- ITUtil.assertResponseLength2CodeOK(response);
- logs = mapper.readValue(response[1], Log[].class);
- assertNotNull(logs);
- assertEquals(4, logs.length);
-
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?description=c*");
- ITUtil.assertResponseLength2CodeOK(response);
- logs = mapper.readValue(response[1], Log[].class);
- assertNotNull(logs);
- assertEquals(18, logs.length);
+ // ----------------------------------------------------------------------------------------------------
+
+ // desc, description, text
+ // quoted strings will be mapped to a phrase query
+ ITUtilLogs.assertListLogs("?desc", 60);
+ ITUtilLogs.assertListLogs("?desc=", 60);
+ ITUtilLogs.assertListLogs("?desc=asdf", 0);
+ ITUtilLogs.assertListLogs("?desc=Initial", 2);
+ ITUtilLogs.assertListLogs("?desc=check", 0);
+ ITUtilLogs.assertListLogs("?desc=Check", 0);
+ ITUtilLogs.assertListLogs("?desc=complete", 0);
+ ITUtilLogs.assertListLogs("?desc=Complete", 0);
+ ITUtilLogs.assertListLogs("?desc=check&desc=complete", 0);
+ ITUtilLogs.assertListLogs("?desc=check complete", HttpURLConnection.HTTP_BAD_REQUEST, -1, -1);
+ ITUtilLogs.assertListLogs("?desc='check complete'", HttpURLConnection.HTTP_BAD_REQUEST, -1, -1);
+ ITUtilLogs.assertListLogs("?desc=" + URLEncoder.encode("check complete", StandardCharsets.UTF_8), 0);
+ ITUtilLogs.assertListLogs("?desc='" + URLEncoder.encode("check complete", StandardCharsets.UTF_8) + "'", 0);
+ ITUtilLogs.assertListLogs("?desc=" + URLEncoder.encode("CHECK COMPLETE", StandardCharsets.UTF_8), 0);
+ ITUtilLogs.assertListLogs("?desc='" + URLEncoder.encode("CHECK COMPLETE", StandardCharsets.UTF_8) + "'", 0);
+ ITUtilLogs.assertListLogs("?desc=chec?", 0);
+ ITUtilLogs.assertListLogs("?desc=?omplete", 0);
+ ITUtilLogs.assertListLogs("?desc=c*", 9);
+ ITUtilLogs.assertListLogs("?desc=Maintenance", 17);
+ ITUtilLogs.assertListLogs("?desc=maintenance", 17);
+ ITUtilLogs.assertListLogs("?desc=after", 3);
+ ITUtilLogs.assertListLogs("?desc=Maintenance&desc=after", 3);
+ ITUtilLogs.assertListLogs("?desc=maintenance&desc=after", 3);
+ ITUtilLogs.assertListLogs("?desc=after&desc=maintenance", 3);
+ ITUtilLogs.assertListLogs("?desc=after&desc=Maintenance", 3);
+ ITUtilLogs.assertListLogs("?desc=" + URLEncoder.encode("after maintenance", StandardCharsets.UTF_8), 3);
+ ITUtilLogs.assertListLogs("?desc='" + URLEncoder.encode("after maintenance", StandardCharsets.UTF_8) + "'", 0);
+ ITUtilLogs.assertListLogs("?desc=\"" + URLEncoder.encode("after maintenance", StandardCharsets.UTF_8) + "\"", HttpURLConnection.HTTP_BAD_REQUEST, -1, -1);
+ ITUtilLogs.assertListLogs("?desc=" + URLEncoder.encode("\"after maintenance\"", StandardCharsets.UTF_8), 3);
+ ITUtilLogs.assertListLogs("?desc=" + URLEncoder.encode("\"after mainTENance\"", StandardCharsets.UTF_8), 3);
+ ITUtilLogs.assertListLogs("?desc=" + URLEncoder.encode("\"after mainTENance", StandardCharsets.UTF_8), HttpURLConnection.HTTP_INTERNAL_ERROR, -1, -1);
+ ITUtilLogs.assertListLogs("?desc=" + URLEncoder.encode("after mainTENance\"", StandardCharsets.UTF_8), HttpURLConnection.HTTP_INTERNAL_ERROR, -1, -1);
+
+ ITUtilLogs.assertSearchLogs("?desc", 60);
+ ITUtilLogs.assertSearchLogs("?desc=", 60);
+ ITUtilLogs.assertSearchLogs("?desc=asdf", 0);
+ ITUtilLogs.assertSearchLogs("?desc=Initial", 2);
+ ITUtilLogs.assertSearchLogs("?desc=check", 0);
+ ITUtilLogs.assertSearchLogs("?desc=Check", 0);
+ ITUtilLogs.assertSearchLogs("?desc=complete", 0);
+ ITUtilLogs.assertSearchLogs("?desc=Complete", 0);
+ ITUtilLogs.assertSearchLogs("?desc=check&desc=complete", 0);
+ ITUtilLogs.assertSearchLogs("?desc=check complete", HttpURLConnection.HTTP_BAD_REQUEST, -1, -1);
+ ITUtilLogs.assertSearchLogs("?desc='check complete'", HttpURLConnection.HTTP_BAD_REQUEST, -1, -1);
+ ITUtilLogs.assertSearchLogs("?desc=" + URLEncoder.encode("check complete", StandardCharsets.UTF_8), 0);
+ ITUtilLogs.assertSearchLogs("?desc='" + URLEncoder.encode("check complete", StandardCharsets.UTF_8) + "'", 0);
+ ITUtilLogs.assertSearchLogs("?desc=" + URLEncoder.encode("CHECK COMPLETE", StandardCharsets.UTF_8), 0);
+ ITUtilLogs.assertSearchLogs("?desc='" + URLEncoder.encode("CHECK COMPLETE", StandardCharsets.UTF_8) + "'", 0);
+ ITUtilLogs.assertSearchLogs("?desc=chec?", 0);
+ ITUtilLogs.assertSearchLogs("?desc=?omplete", 0);
+ ITUtilLogs.assertSearchLogs("?desc=c*", 9);
+ ITUtilLogs.assertSearchLogs("?desc=Maintenance", 17);
+ ITUtilLogs.assertSearchLogs("?desc=maintenance", 17);
+ ITUtilLogs.assertSearchLogs("?desc=after", 3);
+ ITUtilLogs.assertSearchLogs("?desc=Maintenance&desc=after", 3);
+ ITUtilLogs.assertSearchLogs("?desc=maintenance&desc=after", 3);
+ ITUtilLogs.assertSearchLogs("?desc=after&desc=maintenance", 3);
+ ITUtilLogs.assertSearchLogs("?desc=after&desc=Maintenance", 3);
+ ITUtilLogs.assertSearchLogs("?desc=" + URLEncoder.encode("after maintenance", StandardCharsets.UTF_8), 3);
+ ITUtilLogs.assertSearchLogs("?desc='" + URLEncoder.encode("after maintenance", StandardCharsets.UTF_8) + "'", 0);
+ ITUtilLogs.assertSearchLogs("?desc=\"" + URLEncoder.encode("after maintenance", StandardCharsets.UTF_8) + "\"", HttpURLConnection.HTTP_BAD_REQUEST, -1, -1);
+ ITUtilLogs.assertSearchLogs("?desc=" + URLEncoder.encode("\"after maintenance\"", StandardCharsets.UTF_8), 3);
+ ITUtilLogs.assertSearchLogs("?desc=" + URLEncoder.encode("\"after mainTENance\"", StandardCharsets.UTF_8), 3);
+ ITUtilLogs.assertSearchLogs("?desc=" + URLEncoder.encode("\"after mainTENance", StandardCharsets.UTF_8), HttpURLConnection.HTTP_INTERNAL_ERROR, -1, -1);
+ ITUtilLogs.assertSearchLogs("?desc=" + URLEncoder.encode("after mainTENance\"", StandardCharsets.UTF_8), HttpURLConnection.HTTP_INTERNAL_ERROR, -1, -1);
+
+ // ----------------------------------------------------------------------------------------------------
// title
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?title");
- ITUtil.assertResponseLength2CodeOKContent(response, ITUtil.EMPTY_JSON);
-
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?title=asdf");
- ITUtil.assertResponseLength2CodeOKContent(response, ITUtil.EMPTY_JSON);
-
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?title=shift");
- ITUtil.assertResponseLength2CodeOK(response);
- logs = mapper.readValue(response[1], Log[].class);
- assertNotNull(logs);
- assertEquals(43, logs.length);
-
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?title=Shift");
- ITUtil.assertResponseLength2CodeOK(response);
- logs = mapper.readValue(response[1], Log[].class);
- assertNotNull(logs);
- assertEquals(43, logs.length);
-
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?title=update");
- ITUtil.assertResponseLength2CodeOK(response);
- logs = mapper.readValue(response[1], Log[].class);
- assertNotNull(logs);
- assertEquals(37, logs.length);
-
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?title=Update");
- ITUtil.assertResponseLength2CodeOK(response);
- logs = mapper.readValue(response[1], Log[].class);
- assertNotNull(logs);
- assertEquals(37, logs.length);
-
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?title=shift update");
- ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_VERSION);
-
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?title='shift update'");
- ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_VERSION);
-
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?title=shift&title=update");
- ITUtil.assertResponseLength2CodeOK(response);
- logs = mapper.readValue(response[1], Log[].class);
- assertNotNull(logs);
- assertEquals(43, logs.length);
-
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?title="+URLEncoder.encode("shift update", StandardCharsets.UTF_8));
- ITUtil.assertResponseLength2CodeOK(response);
- logs = mapper.readValue(response[1], Log[].class);
- assertNotNull(logs);
- assertEquals(43, logs.length);
-
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?title='"+URLEncoder.encode("shift update", StandardCharsets.UTF_8)+"'");
- ITUtil.assertResponseLength2CodeOKContent(response, ITUtil.EMPTY_JSON);
-
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?title="+URLEncoder.encode("SHIFT UPDATE", StandardCharsets.UTF_8));
- ITUtil.assertResponseLength2CodeOK(response);
- logs = mapper.readValue(response[1], Log[].class);
- assertNotNull(logs);
- assertEquals(43, logs.length);
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?title='"+URLEncoder.encode("SHIFT UPDATE", StandardCharsets.UTF_8)+"'");
- ITUtil.assertResponseLength2CodeOKContent(response, ITUtil.EMPTY_JSON);
-
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?title=Shif?");
- ITUtil.assertResponseLength2CodeOK(response);
- logs = mapper.readValue(response[1], Log[].class);
- assertNotNull(logs);
- assertEquals(43, logs.length);
-
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?title=??ift");
- ITUtil.assertResponseLength2CodeOK(response);
- logs = mapper.readValue(response[1], Log[].class);
- assertNotNull(logs);
- assertEquals(43, logs.length);
-
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?title=S*t");
- ITUtil.assertResponseLength2CodeOK(response);
- logs = mapper.readValue(response[1], Log[].class);
- assertNotNull(logs);
- assertEquals(43, logs.length);
-
- // level
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?level");
- ITUtil.assertResponseLength2CodeOKContent(response, ITUtil.EMPTY_JSON);
-
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?level=asdf");
- ITUtil.assertResponseLength2CodeOKContent(response, ITUtil.EMPTY_JSON);
-
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?level=shift");
- ITUtil.assertResponseLength2CodeOK(response);
- logs = mapper.readValue(response[1], Log[].class);
- assertNotNull(logs);
- assertEquals(60, logs.length);
-
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?level=Shift");
- ITUtil.assertResponseLength2CodeOK(response);
- logs = mapper.readValue(response[1], Log[].class);
- assertNotNull(logs);
- assertEquals(60, logs.length);
-
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?level=update");
- ITUtil.assertResponseLength2CodeOK(response);
- logs = mapper.readValue(response[1], Log[].class);
- assertNotNull(logs);
- assertEquals(54, logs.length);
-
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?level=Update");
- ITUtil.assertResponseLength2CodeOK(response);
- logs = mapper.readValue(response[1], Log[].class);
- assertNotNull(logs);
- assertEquals(54, logs.length);
-
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?level=shift update");
- ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_VERSION);
-
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?level='shift update'");
- ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_VERSION);
-
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?level=shift&level=update");
- ITUtil.assertResponseLength2CodeOK(response);
- logs = mapper.readValue(response[1], Log[].class);
- assertNotNull(logs);
- assertEquals(60, logs.length);
-
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?level="+URLEncoder.encode("shift update", StandardCharsets.UTF_8));
- ITUtil.assertResponseLength2CodeOK(response);
- logs = mapper.readValue(response[1], Log[].class);
- assertNotNull(logs);
- assertEquals(60, logs.length);
-
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?level='"+URLEncoder.encode("shift update", StandardCharsets.UTF_8)+"'");
- ITUtil.assertResponseLength2CodeOKContent(response, ITUtil.EMPTY_JSON);
-
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?level="+URLEncoder.encode("SHIFT UPDATE", StandardCharsets.UTF_8));
- ITUtil.assertResponseLength2CodeOK(response);
- logs = mapper.readValue(response[1], Log[].class);
- assertNotNull(logs);
- assertEquals(60, logs.length);
-
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?level='"+URLEncoder.encode("SHIFT UPDATE", StandardCharsets.UTF_8)+"'");
- ITUtil.assertResponseLength2CodeOKContent(response, ITUtil.EMPTY_JSON);
-
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?level=?pdate");
- ITUtil.assertResponseLength2CodeOK(response);
- logs = mapper.readValue(response[1], Log[].class);
- assertNotNull(logs);
- assertEquals(54, logs.length);
-
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?level=upd??e");
- ITUtil.assertResponseLength2CodeOK(response);
- logs = mapper.readValue(response[1], Log[].class);
- assertNotNull(logs);
- assertEquals(54, logs.length);
-
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?level=*ate");
- ITUtil.assertResponseLength2CodeOK(response);
- logs = mapper.readValue(response[1], Log[].class);
- assertNotNull(logs);
- assertEquals(54, logs.length);
-
- // phrase
- // phrase for description
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?phrase");
- ITUtil.assertResponseLength2CodeOKContent(response, ITUtil.EMPTY_JSON);
-
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?phrase=asdf");
- ITUtil.assertResponseLength2CodeOKContent(response, ITUtil.EMPTY_JSON);
-
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?phrase=check");
- ITUtil.assertResponseLength2CodeOK(response);
- logs = mapper.readValue(response[1], Log[].class);
- assertNotNull(logs);
- assertEquals(8, logs.length);
-
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?phrase=Check");
- ITUtil.assertResponseLength2CodeOK(response);
- logs = mapper.readValue(response[1], Log[].class);
- assertNotNull(logs);
- assertEquals(8, logs.length);
-
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?phrase=complete");
- ITUtil.assertResponseLength2CodeOK(response);
- logs = mapper.readValue(response[1], Log[].class);
- assertNotNull(logs);
- assertEquals(4, logs.length);
-
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?phrase=Complete");
- ITUtil.assertResponseLength2CodeOK(response);
- logs = mapper.readValue(response[1], Log[].class);
- assertNotNull(logs);
- assertEquals(4, logs.length);
-
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?phrase=check complete");
- ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_VERSION);
-
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?phrase='check complete'");
- ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_VERSION);
-
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?phrase=check&phrase=complete");
- ITUtil.assertResponseLength2CodeOK(response);
- logs = mapper.readValue(response[1], Log[].class);
- assertNotNull(logs);
- assertEquals(10, logs.length);
-
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?phrase="+URLEncoder.encode("check complete", StandardCharsets.UTF_8));
- ITUtil.assertResponseLength2CodeOK(response);
- logs = mapper.readValue(response[1], Log[].class);
- assertNotNull(logs);
- assertEquals(2, logs.length);
-
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?phrase='"+URLEncoder.encode("check complete", StandardCharsets.UTF_8)+"'");
- ITUtil.assertResponseLength2CodeOK(response);
- logs = mapper.readValue(response[1], Log[].class);
- assertNotNull(logs);
- assertEquals(2, logs.length);
-
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?phrase="+URLEncoder.encode("CHECK COMPLETE", StandardCharsets.UTF_8));
- ITUtil.assertResponseLength2CodeOK(response);
- logs = mapper.readValue(response[1], Log[].class);
- assertNotNull(logs);
- assertEquals(2, logs.length);
-
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?phrase='"+URLEncoder.encode("CHECK COMPLETE", StandardCharsets.UTF_8)+"'");
- ITUtil.assertResponseLength2CodeOK(response);
- logs = mapper.readValue(response[1], Log[].class);
- assertNotNull(logs);
- assertEquals(2, logs.length);
+ // quoted strings will be mapped to a phrase query
+ ITUtilLogs.assertListLogs("?title", 60);
+ ITUtilLogs.assertListLogs("?title=", 60);
+ ITUtilLogs.assertListLogs("?title=asdf", 0);
+ ITUtilLogs.assertListLogs("?title=shift", 43);
+ ITUtilLogs.assertListLogs("?title=Shift", 43);
+ ITUtilLogs.assertListLogs("?title=update", 37);
+ ITUtilLogs.assertListLogs("?title=Update", 37);
+ ITUtilLogs.assertListLogs("?title=shift&title=update", 37);
+ ITUtilLogs.assertListLogs("?title=shift update", HttpURLConnection.HTTP_BAD_REQUEST, -1, -1);
+ ITUtilLogs.assertListLogs("?title='shift update'", HttpURLConnection.HTTP_BAD_REQUEST, -1, -1);
+ ITUtilLogs.assertListLogs("?title=" + URLEncoder.encode("\"Shift Update\"", StandardCharsets.UTF_8), 37);
+ ITUtilLogs.assertListLogs("?title=" + URLEncoder.encode("\"shiFT updATE\"", StandardCharsets.UTF_8), 37);
+ ITUtilLogs.assertListLogs("?title=" + URLEncoder.encode("shiFT updATE\"", StandardCharsets.UTF_8), HttpURLConnection.HTTP_INTERNAL_ERROR, -1, -1);
+ ITUtilLogs.assertListLogs("?title=" + URLEncoder.encode("\"shiFT updATE", StandardCharsets.UTF_8), HttpURLConnection.HTTP_INTERNAL_ERROR, -1, -1);
+ ITUtilLogs.assertListLogs("?title=" + URLEncoder.encode("shift update", StandardCharsets.UTF_8), 37);
+ ITUtilLogs.assertListLogs("?title='" + URLEncoder.encode("shift update", StandardCharsets.UTF_8) + "'", 0);
+ ITUtilLogs.assertListLogs("?title=" + URLEncoder.encode("SHIFT UPDATE", StandardCharsets.UTF_8), 37);
+ ITUtilLogs.assertListLogs("?title='" + URLEncoder.encode("SHIFT UPDATE", StandardCharsets.UTF_8) + "'", 0);
+ ITUtilLogs.assertListLogs("?title=Shif?", 43);
+ ITUtilLogs.assertListLogs("?title=??ift", 43);
+ ITUtilLogs.assertListLogs("?title=S*t", 43);
+
+ ITUtilLogs.assertSearchLogs("?title", 60);
+ ITUtilLogs.assertSearchLogs("?title=", 60);
+ ITUtilLogs.assertSearchLogs("?title=asdf", 0);
+ ITUtilLogs.assertSearchLogs("?title=shift", 43);
+ ITUtilLogs.assertSearchLogs("?title=Shift", 43);
+ ITUtilLogs.assertSearchLogs("?title=update", 37);
+ ITUtilLogs.assertSearchLogs("?title=Update", 37);
+ ITUtilLogs.assertSearchLogs("?title=shift&title=update", 37);
+ ITUtilLogs.assertSearchLogs("?title=shift update", HttpURLConnection.HTTP_BAD_REQUEST, -1, -1);
+ ITUtilLogs.assertSearchLogs("?title='shift update'", HttpURLConnection.HTTP_BAD_REQUEST, -1, -1);
+ ITUtilLogs.assertSearchLogs("?title=" + URLEncoder.encode("\"Shift Update\"", StandardCharsets.UTF_8), 37);
+ ITUtilLogs.assertSearchLogs("?title=" + URLEncoder.encode("\"shiFT updATE\"", StandardCharsets.UTF_8), 37);
+ ITUtilLogs.assertSearchLogs("?title=" + URLEncoder.encode("shiFT updATE\"", StandardCharsets.UTF_8), HttpURLConnection.HTTP_INTERNAL_ERROR, -1, -1);
+ ITUtilLogs.assertSearchLogs("?title=" + URLEncoder.encode("\"shiFT updATE", StandardCharsets.UTF_8), HttpURLConnection.HTTP_INTERNAL_ERROR, -1, -1);
+ ITUtilLogs.assertSearchLogs("?title=" + URLEncoder.encode("shift update", StandardCharsets.UTF_8), 37);
+ ITUtilLogs.assertSearchLogs("?title='" + URLEncoder.encode("shift update", StandardCharsets.UTF_8) + "'", 0);
+ ITUtilLogs.assertSearchLogs("?title=" + URLEncoder.encode("SHIFT UPDATE", StandardCharsets.UTF_8), 37);
+ ITUtilLogs.assertSearchLogs("?title='" + URLEncoder.encode("SHIFT UPDATE", StandardCharsets.UTF_8) + "'", 0);
+ ITUtilLogs.assertSearchLogs("?title=Shif?", 43);
+ ITUtilLogs.assertSearchLogs("?title=??ift", 43);
+ ITUtilLogs.assertSearchLogs("?title=S*t", 43);
+
+ // ----------------------------------------------------------------------------------------------------
// fuzzy
// fuzziness AUTO
// description
// title
// level
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?fuzzy");
- ITUtil.assertResponseLength2CodeOK(response);
- logs = mapper.readValue(response[1], Log[].class);
- assertNotNull(logs);
- assertEquals(60, logs.length);
-
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?fuzzy&description=cmplete");
- ITUtil.assertResponseLength2CodeOK(response);
- logs = mapper.readValue(response[1], Log[].class);
- assertNotNull(logs);
- assertEquals(4, logs.length);
-
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?fuzzy&description=cmplte");
- ITUtil.assertResponseLength2CodeOK(response);
- logs = mapper.readValue(response[1], Log[].class);
- assertNotNull(logs);
- assertEquals(4, logs.length);
-
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?fuzzy&title=Shif");
- ITUtil.assertResponseLength2CodeOK(response);
- logs = mapper.readValue(response[1], Log[].class);
- assertNotNull(logs);
- assertEquals(43, logs.length);
-
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?fuzzy&title=Shif?");
- ITUtil.assertResponseLength2CodeOK(response);
- logs = mapper.readValue(response[1], Log[].class);
- assertNotNull(logs);
- assertEquals(43, logs.length);
-
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?fuzzy&title=Shif*");
- ITUtil.assertResponseLength2CodeOK(response);
- logs = mapper.readValue(response[1], Log[].class);
- assertNotNull(logs);
- assertEquals(43, logs.length);
-
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?fuzzy&title=Shi??");
- ITUtil.assertResponseLength2CodeOKContent(response, ITUtil.EMPTY_JSON);
-
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?fuzzy&title=hif");
- ITUtil.assertResponseLength2CodeOKContent(response, ITUtil.EMPTY_JSON);
-
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?fuzzy&level=pdate");
- ITUtil.assertResponseLength2CodeOK(response);
- logs = mapper.readValue(response[1], Log[].class);
- assertNotNull(logs);
- assertEquals(54, logs.length);
-
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?fuzzy&level=Upd");
- ITUtil.assertResponseLength2CodeOKContent(response, ITUtil.EMPTY_JSON);
-
- // meta data
- // logbooks
- // name
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?logbooks");
- ITUtil.assertResponseLength2CodeOKContent(response, ITUtil.EMPTY_JSON);
-
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?logbooks=asdf");
- ITUtil.assertResponseLength2CodeOKContent(response, ITUtil.EMPTY_JSON);
-
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?logbooks=Buildings");
- ITUtil.assertResponseLength2CodeOKContent(response, ITUtil.EMPTY_JSON);
-
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?logbooks=Communication");
- ITUtil.assertResponseLength2CodeOKContent(response, ITUtil.EMPTY_JSON);
-
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?logbooks=Experiments");
- ITUtil.assertResponseLength2CodeOKContent(response, ITUtil.EMPTY_JSON);
-
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?logbooks=Facilities");
- ITUtil.assertResponseLength2CodeOKContent(response, ITUtil.EMPTY_JSON);
+ ITUtilLogs.assertListLogs("?fuzzy", 60);
+ ITUtilLogs.assertListLogs("?fuzzy=", 60);
+ ITUtilLogs.assertListLogs("?fuzzy&description=cmplete", 0);
+ ITUtilLogs.assertListLogs("?fuzzy&description=cmplte", 0);
+ ITUtilLogs.assertListLogs("?fuzzy&title=Shift", 43);
+ ITUtilLogs.assertListLogs("?fuzzy&title=Shif", 43);
+ ITUtilLogs.assertListLogs("?fuzzy&title=Shif?", 43);
+ ITUtilLogs.assertListLogs("?fuzzy&title=Shif*", 43);
+ ITUtilLogs.assertListLogs("?fuzzy&title=Shi??", 0);
+ ITUtilLogs.assertListLogs("?fuzzy&title=hif", 0);
+ ITUtilLogs.assertListLogs("?fuzzy&level=Update", 54);
+ ITUtilLogs.assertListLogs("?fuzzy&level=pdate", 54);
+ ITUtilLogs.assertListLogs("?fuzzy&level=Upd", 0);
+
+ ITUtilLogs.assertSearchLogs("?fuzzy", 60);
+ ITUtilLogs.assertSearchLogs("?fuzzy=", 60);
+ ITUtilLogs.assertSearchLogs("?fuzzy&description=cmplete", 0);
+ ITUtilLogs.assertSearchLogs("?fuzzy&description=cmplte", 0);
+ ITUtilLogs.assertSearchLogs("?fuzzy&title=Shift", 43);
+ ITUtilLogs.assertSearchLogs("?fuzzy&title=Shif", 43);
+ ITUtilLogs.assertSearchLogs("?fuzzy&title=Shif?", 43);
+ ITUtilLogs.assertSearchLogs("?fuzzy&title=Shif*", 43);
+ ITUtilLogs.assertSearchLogs("?fuzzy&title=Shi??", 0);
+ ITUtilLogs.assertSearchLogs("?fuzzy&title=hif", 0);
+ ITUtilLogs.assertSearchLogs("?fuzzy&level=Update", 54);
+ ITUtilLogs.assertSearchLogs("?fuzzy&level=pdate", 54);
+ ITUtilLogs.assertSearchLogs("?fuzzy&level=Upd", 0);
+
+ // ----------------------------------------------------------------------------------------------------
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?logbooks=Maintenance");
- ITUtil.assertResponseLength2CodeOK(response);
- logs = mapper.readValue(response[1], Log[].class);
- assertNotNull(logs);
- assertEquals(17, logs.length);
-
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?logbooks=operations");
- ITUtil.assertResponseLength2CodeOKContent(response, ITUtil.EMPTY_JSON);
-
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?logbooks=Operations");
- ITUtil.assertResponseLength2CodeOK(response);
- logs = mapper.readValue(response[1], Log[].class);
- assertNotNull(logs);
- assertEquals(49, logs.length);
-
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?logbooks=operation");
- ITUtil.assertResponseLength2CodeOKContent(response, ITUtil.EMPTY_JSON);
-
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?logbooks=Power");
- ITUtil.assertResponseLength2CodeOK(response);
- logs = mapper.readValue(response[1], Log[].class);
- assertNotNull(logs);
- assertEquals(2, logs.length);
-
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?logbooks=Services");
- ITUtil.assertResponseLength2CodeOKContent(response, ITUtil.EMPTY_JSON);
-
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?logbooks=Water");
- ITUtil.assertResponseLength2CodeOKContent(response, ITUtil.EMPTY_JSON);
-
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?logbooks=Maintenance&logbooks=Power");
- ITUtil.assertResponseLength2CodeOK(response);
- logs = mapper.readValue(response[1], Log[].class);
- assertNotNull(logs);
- assertEquals(18, logs.length);
-
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?logbooks=Maint*");
- ITUtil.assertResponseLength2CodeOK(response);
- logs = mapper.readValue(response[1], Log[].class);
- assertNotNull(logs);
- assertEquals(17, logs.length);
-
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?logbooks=?e?");
- ITUtil.assertResponseLength2CodeOKContent(response, ITUtil.EMPTY_JSON);
-
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?logbooks=*e*");
- ITUtil.assertResponseLength2CodeOK(response);
- logs = mapper.readValue(response[1], Log[].class);
- assertNotNull(logs);
- assertEquals(60, logs.length);
+ // phrase
+ // phrase for description
+ ITUtilLogs.assertListLogs("?phrase", 0);
+ ITUtilLogs.assertListLogs("?phrase=", 0);
+ ITUtilLogs.assertListLogs("?phrase=asdf", 0);
+ ITUtilLogs.assertListLogs("?phrase=Initial", 2);
+ ITUtilLogs.assertListLogs("?phrase=check", 0);
+ ITUtilLogs.assertListLogs("?phrase=Check", 0);
+ ITUtilLogs.assertListLogs("?phrase=complete", 0);
+ ITUtilLogs.assertListLogs("?phrase=Complete", 0);
+ ITUtilLogs.assertListLogs("?phrase=check&phrase=complete", 0);
+ ITUtilLogs.assertListLogs("?phrase=check complete", HttpURLConnection.HTTP_BAD_REQUEST, -1, -1);
+ ITUtilLogs.assertListLogs("?phrase='check complete'", HttpURLConnection.HTTP_BAD_REQUEST, -1, -1);
+ ITUtilLogs.assertListLogs("?phrase=" + URLEncoder.encode("check complete", StandardCharsets.UTF_8), 0);
+ ITUtilLogs.assertListLogs("?phrase='" + URLEncoder.encode("check complete", StandardCharsets.UTF_8) + "'", 0);
+ ITUtilLogs.assertListLogs("?phrase=" + URLEncoder.encode("CHECK COMPLETE", StandardCharsets.UTF_8), 0);
+ ITUtilLogs.assertListLogs("?phrase='" + URLEncoder.encode("CHECK COMPLETE", StandardCharsets.UTF_8) + "'", 0);
+
+ ITUtilLogs.assertSearchLogs("?phrase", 0);
+ ITUtilLogs.assertSearchLogs("?phrase=", 0);
+ ITUtilLogs.assertSearchLogs("?phrase=asdf", 0);
+ ITUtilLogs.assertSearchLogs("?phrase=Initial", 2);
+ ITUtilLogs.assertSearchLogs("?phrase=check", 0);
+ ITUtilLogs.assertSearchLogs("?phrase=Check", 0);
+ ITUtilLogs.assertSearchLogs("?phrase=complete", 0);
+ ITUtilLogs.assertSearchLogs("?phrase=Complete", 0);
+ ITUtilLogs.assertSearchLogs("?phrase=check&phrase=complete", 0);
+ ITUtilLogs.assertSearchLogs("?phrase=check complete", HttpURLConnection.HTTP_BAD_REQUEST, -1, -1);
+ ITUtilLogs.assertSearchLogs("?phrase='check complete'", HttpURLConnection.HTTP_BAD_REQUEST, -1, -1);
+ ITUtilLogs.assertSearchLogs("?phrase=" + URLEncoder.encode("check complete", StandardCharsets.UTF_8), 0);
+ ITUtilLogs.assertSearchLogs("?phrase='" + URLEncoder.encode("check complete", StandardCharsets.UTF_8) + "'", 0);
+ ITUtilLogs.assertSearchLogs("?phrase=" + URLEncoder.encode("CHECK COMPLETE", StandardCharsets.UTF_8), 0);
+ ITUtilLogs.assertSearchLogs("?phrase='" + URLEncoder.encode("CHECK COMPLETE", StandardCharsets.UTF_8) + "'", 0);
+
+ // ----------------------------------------------------------------------------------------------------
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?logbooks=x*x");
- ITUtil.assertResponseLength2CodeOKContent(response, ITUtil.EMPTY_JSON);
+ // owner
+ ITUtilLogs.assertListLogs("?owner", 0);
+ ITUtilLogs.assertListLogs("?owner=asdf", 0);
+ ITUtilLogs.assertListLogs("?owner=admin", 60);
+ ITUtilLogs.assertListLogs("?owner=adm?n", 60);
+ ITUtilLogs.assertListLogs("?owner=adm?m", 0);
+ ITUtilLogs.assertListLogs("?owner=adm*", 60);
+
+ ITUtilLogs.assertSearchLogs("?owner", 0);
+ ITUtilLogs.assertSearchLogs("?owner=asdf", 0);
+ ITUtilLogs.assertSearchLogs("?owner=admin", 60);
+ ITUtilLogs.assertSearchLogs("?owner=adm?n", 60);
+ ITUtilLogs.assertSearchLogs("?owner=adm?m", 0);
+ ITUtilLogs.assertSearchLogs("?owner=adm*", 60);
+
+ // ----------------------------------------------------------------------------------------------------
// tags
// name
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?tags");
- ITUtil.assertResponseLength2CodeOKContent(response, ITUtil.EMPTY_JSON);
-
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?tags=asdf");
- ITUtil.assertResponseLength2CodeOKContent(response, ITUtil.EMPTY_JSON);
-
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?tags=cryo");
- ITUtil.assertResponseLength2CodeOKContent(response, ITUtil.EMPTY_JSON);
-
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?tags=Cryo");
- ITUtil.assertResponseLength2CodeOK(response);
- logs = mapper.readValue(response[1], Log[].class);
- assertNotNull(logs);
- assertEquals(10, logs.length);
-
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?tags=Cry");
- ITUtil.assertResponseLength2CodeOKContent(response, ITUtil.EMPTY_JSON);
-
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?tags=Power");
- ITUtil.assertResponseLength2CodeOK(response);
- logs = mapper.readValue(response[1], Log[].class);
- assertNotNull(logs);
- assertEquals(2, logs.length);
-
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?tags=Safety");
- ITUtil.assertResponseLength2CodeOK(response);
- logs = mapper.readValue(response[1], Log[].class);
- assertNotNull(logs);
- assertEquals(2, logs.length);
-
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?tags=Source");
- ITUtil.assertResponseLength2CodeOK(response);
- logs = mapper.readValue(response[1], Log[].class);
- assertNotNull(logs);
- assertEquals(2, logs.length);
-
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?tags=Initial");
- ITUtil.assertResponseLength2CodeOK(response);
- logs = mapper.readValue(response[1], Log[].class);
- assertNotNull(logs);
- assertEquals(2, logs.length);
-
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?tags=Radio");
- ITUtil.assertResponseLength2CodeOK(response);
- logs = mapper.readValue(response[1], Log[].class);
- assertNotNull(logs);
- assertEquals(2, logs.length);
-
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?tags=Magnet");
- ITUtil.assertResponseLength2CodeOK(response);
- logs = mapper.readValue(response[1], Log[].class);
- assertNotNull(logs);
- assertEquals(2, logs.length);
-
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?tags=Supra");
- ITUtil.assertResponseLength2CodeOK(response);
- logs = mapper.readValue(response[1], Log[].class);
- assertNotNull(logs);
- assertEquals(3, logs.length);
-
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?tags=Magnet&tags=Supra");
- ITUtil.assertResponseLength2CodeOK(response);
- logs = mapper.readValue(response[1], Log[].class);
- assertNotNull(logs);
- assertEquals(5, logs.length);
-
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?tags=?ryo");
- ITUtil.assertResponseLength2CodeOK(response);
- logs = mapper.readValue(response[1], Log[].class);
- assertNotNull(logs);
- assertEquals(10, logs.length);
-
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?tags=*yo");
- ITUtil.assertResponseLength2CodeOK(response);
- logs = mapper.readValue(response[1], Log[].class);
- assertNotNull(logs);
- assertEquals(10, logs.length);
-
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?tags=C???");
- ITUtil.assertResponseLength2CodeOK(response);
- logs = mapper.readValue(response[1], Log[].class);
- assertNotNull(logs);
- assertEquals(10, logs.length);
+ ITUtilLogs.assertListLogs("?tags", 0);
+ ITUtilLogs.assertListLogs("?tags=", 0);
+ ITUtilLogs.assertListLogs("?tags=asdf", 0);
+ ITUtilLogs.assertListLogs("?tags=cryo", 10);
+ ITUtilLogs.assertListLogs("?tags=Cryo", 10);
+ ITUtilLogs.assertListLogs("?tags=Cry", 0);
+ ITUtilLogs.assertListLogs("?tags=Power", 2);
+ ITUtilLogs.assertListLogs("?tags=Safety", 2);
+ ITUtilLogs.assertListLogs("?tags=Source", 2);
+ ITUtilLogs.assertListLogs("?tags=Initial", 2);
+ ITUtilLogs.assertListLogs("?tags=Radio", 2);
+ ITUtilLogs.assertListLogs("?tags=Magnet", 2);
+ ITUtilLogs.assertListLogs("?tags=Supra", 3);
+ ITUtilLogs.assertListLogs("?tags=Magnet&tags=Supra", 5);
+ ITUtilLogs.assertListLogs("?tags=Magnet,Supra", 5);
+ ITUtilLogs.assertListLogs("?tags=?ryo", 10);
+ ITUtilLogs.assertListLogs("?tags=*yo", 10);
+ ITUtilLogs.assertListLogs("?tags=C???", 10);
+
+ ITUtilLogs.assertSearchLogs("?tags", 0);
+ ITUtilLogs.assertSearchLogs("?tags=", 0);
+ ITUtilLogs.assertSearchLogs("?tags=asdf", 0);
+ ITUtilLogs.assertSearchLogs("?tags=cryo", 10);
+ ITUtilLogs.assertSearchLogs("?tags=Cryo", 10);
+ ITUtilLogs.assertSearchLogs("?tags=Cry", 0);
+ ITUtilLogs.assertSearchLogs("?tags=Power", 2);
+ ITUtilLogs.assertSearchLogs("?tags=Safety", 2);
+ ITUtilLogs.assertSearchLogs("?tags=Source", 2);
+ ITUtilLogs.assertSearchLogs("?tags=Initial", 2);
+ ITUtilLogs.assertSearchLogs("?tags=Radio", 2);
+ ITUtilLogs.assertSearchLogs("?tags=Magnet", 2);
+ ITUtilLogs.assertSearchLogs("?tags=Supra", 3);
+ ITUtilLogs.assertSearchLogs("?tags=Magnet&tags=Supra", 5);
+ ITUtilLogs.assertSearchLogs("?tags=Magnet,Supra", 5);
+ ITUtilLogs.assertSearchLogs("?tags=?ryo", 10);
+ ITUtilLogs.assertSearchLogs("?tags=*yo", 10);
+ ITUtilLogs.assertSearchLogs("?tags=C???", 10);
+
+ // ----------------------------------------------------------------------------------------------------
+
+ // logbooks
+ // name
+ ITUtilLogs.assertListLogs("?logbooks", 0);
+ ITUtilLogs.assertListLogs("?logbooks=", 0);
+ ITUtilLogs.assertListLogs("?logbooks=asdf", 0);
+ ITUtilLogs.assertListLogs("?logbooks=Buildings", 0);
+ ITUtilLogs.assertListLogs("?logbooks=Communication", 0);
+ ITUtilLogs.assertListLogs("?logbooks=Experiments", 0);
+ ITUtilLogs.assertListLogs("?logbooks=Facilities", 0);
+ ITUtilLogs.assertListLogs("?logbooks=Maintenance", 17);
+ ITUtilLogs.assertListLogs("?logbooks=operations", 49);
+ ITUtilLogs.assertListLogs("?logbooks=Operations", 49);
+ ITUtilLogs.assertListLogs("?logbooks=operation", 0);
+ ITUtilLogs.assertListLogs("?logbooks=Power", 2);
+ ITUtilLogs.assertListLogs("?logbooks=Services", 0);
+ ITUtilLogs.assertListLogs("?logbooks=Water", 0);
+ ITUtilLogs.assertListLogs("?logbooks=Maintenance&logbooks=Power", 18);
+ ITUtilLogs.assertListLogs("?logbooks=Maintenance,Power", 18);
+ ITUtilLogs.assertListLogs("?logbooks=Maint*", 17);
+ ITUtilLogs.assertListLogs("?logbooks=?e?", 0);
+ ITUtilLogs.assertListLogs("?logbooks=*e*", 60);
+ ITUtilLogs.assertListLogs("?logbooks=x*x", 0);
+
+ ITUtilLogs.assertSearchLogs("?logbooks", 0);
+ ITUtilLogs.assertSearchLogs("?logbooks=", 0);
+ ITUtilLogs.assertSearchLogs("?logbooks=asdf", 0);
+ ITUtilLogs.assertSearchLogs("?logbooks=Buildings", 0);
+ ITUtilLogs.assertSearchLogs("?logbooks=Communication", 0);
+ ITUtilLogs.assertSearchLogs("?logbooks=Experiments", 0);
+ ITUtilLogs.assertSearchLogs("?logbooks=Facilities", 0);
+ ITUtilLogs.assertSearchLogs("?logbooks=Maintenance", 17);
+ ITUtilLogs.assertSearchLogs("?logbooks=operations", 49);
+ ITUtilLogs.assertSearchLogs("?logbooks=Operations", 49);
+ ITUtilLogs.assertSearchLogs("?logbooks=operation", 0);
+ ITUtilLogs.assertSearchLogs("?logbooks=Power", 2);
+ ITUtilLogs.assertSearchLogs("?logbooks=Services", 0);
+ ITUtilLogs.assertSearchLogs("?logbooks=Water", 0);
+ ITUtilLogs.assertSearchLogs("?logbooks=Maintenance&logbooks=Power", 18);
+ ITUtilLogs.assertSearchLogs("?logbooks=Maintenance,Power", 18);
+ ITUtilLogs.assertSearchLogs("?logbooks=Maint*", 17);
+ ITUtilLogs.assertSearchLogs("?logbooks=?e?", 0);
+ ITUtilLogs.assertSearchLogs("?logbooks=*e*", 60);
+ ITUtilLogs.assertSearchLogs("?logbooks=x*x", 0);
+
+ // ----------------------------------------------------------------------------------------------------
+
+ // start
+ // end
+ // 60 logs during 24 hours
+ // first timestamp 2007-12-03T10:15:30.00Z
+ // last timestamp 2007-12-04T10:25:30.00Z
+ // DateTimeFormatter MILLI_FORMAT
+ // type 2 weeks, see now
+ // intended and unintended usage, positive and negative tests
+ ITUtilLogs.assertListLogs("?start", 0);
+ ITUtilLogs.assertListLogs("?start=asdf", 60);
+ ITUtilLogs.assertListLogs("?end", 60);
+ ITUtilLogs.assertListLogs("?end=asdf", 0);
+ ITUtilLogs.assertListLogs("?start&includeevents", 0);
+ ITUtilLogs.assertListLogs("?start=asdf&includeevents", 60);
+ ITUtilLogs.assertListLogs("?end&includeevents", 60);
+ ITUtilLogs.assertListLogs("?end=asdf&includeevents", 0);
+
+ ITUtilLogs.assertListLogs("?start=2007-12-01T00:00:00.00Z", 0);
+ ITUtilLogs.assertListLogs("?start=2007-12-03T00:00:00.00Z", 0);
+ ITUtilLogs.assertListLogs("?start=2007-12-03T10:15:30.00Z", 0);
+ ITUtilLogs.assertListLogs("?start=2007-12-04T00:00:00.00Z", 0);
+ ITUtilLogs.assertListLogs("?start=2007-12-04T10:25:30.00Z", 0);
+ ITUtilLogs.assertListLogs("?start=2007-12-05T00:00:00.00Z", 0);
+ ITUtilLogs.assertListLogs("?start=2007-12-07T00:00:00.00Z", 0);
+ ITUtilLogs.assertListLogs("?end=2007-12-01T00:00:00.00Z", 60);
+ ITUtilLogs.assertListLogs("?end=2007-12-03T00:00:00.00Z", 60);
+ ITUtilLogs.assertListLogs("?end=2007-12-03T10:15:30.00Z", 60);
+ ITUtilLogs.assertListLogs("?end=2007-12-04T00:00:00.00Z", 60);
+ ITUtilLogs.assertListLogs("?end=2007-12-04T10:25:30.00Z", 60);
+ ITUtilLogs.assertListLogs("?end=2007-12-05T00:00:00.00Z", 60);
+ ITUtilLogs.assertListLogs("?end=2007-12-07T00:00:00.00Z", 60);
+ ITUtilLogs.assertListLogs("?start=2007-12-07T00:00:00.00Z&end=2007-12-01T00:00:00.00Z", 0);
+
+ ITUtilLogs.assertSearchLogs("?start", 0);
+ ITUtilLogs.assertSearchLogs("?start=asdf", 60);
+ ITUtilLogs.assertSearchLogs("?end", 60);
+ ITUtilLogs.assertSearchLogs("?end=asdf", 0);
+ ITUtilLogs.assertSearchLogs("?start&includeevents", 0);
+ ITUtilLogs.assertSearchLogs("?start=asdf&includeevents", 60);
+ ITUtilLogs.assertSearchLogs("?end&includeevents", 60);
+ ITUtilLogs.assertSearchLogs("?end=asdf&includeevents", 0);
+
+ ITUtilLogs.assertSearchLogs("?start=2007-12-01T00:00:00.00Z", 0);
+ ITUtilLogs.assertSearchLogs("?start=2007-12-03T00:00:00.00Z", 0);
+ ITUtilLogs.assertSearchLogs("?start=2007-12-03T10:15:30.00Z", 0);
+ ITUtilLogs.assertSearchLogs("?start=2007-12-04T00:00:00.00Z", 0);
+ ITUtilLogs.assertSearchLogs("?start=2007-12-04T10:25:30.00Z", 0);
+ ITUtilLogs.assertSearchLogs("?start=2007-12-05T00:00:00.00Z", 0);
+ ITUtilLogs.assertSearchLogs("?start=2007-12-07T00:00:00.00Z", 0);
+ ITUtilLogs.assertSearchLogs("?end=2007-12-01T00:00:00.00Z", 60);
+ ITUtilLogs.assertSearchLogs("?end=2007-12-03T00:00:00.00Z", 60);
+ ITUtilLogs.assertSearchLogs("?end=2007-12-03T10:15:30.00Z", 60);
+ ITUtilLogs.assertSearchLogs("?end=2007-12-04T00:00:00.00Z", 60);
+ ITUtilLogs.assertSearchLogs("?end=2007-12-04T10:25:30.00Z", 60);
+ ITUtilLogs.assertSearchLogs("?end=2007-12-05T00:00:00.00Z", 60);
+ ITUtilLogs.assertSearchLogs("?end=2007-12-07T00:00:00.00Z", 60);
+ ITUtilLogs.assertSearchLogs("?start=2007-12-07T00:00:00.00Z&end=2007-12-01T00:00:00.00Z", 0);
+
+ // ----------------------------------------------------------------------------------------------------
+
+ // includeevents, includeevent
+ ITUtilLogs.assertListLogs("?includeevents", 60);
+
+ ITUtilLogs.assertSearchLogs("?includeevents", 60);
+
+ // ----------------------------------------------------------------------------------------------------
// properties
// name
// attribute name
// attribute value
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?properties");
- ITUtil.assertResponseLength2CodeOK(response);
- logs = mapper.readValue(response[1], Log[].class);
- assertNotNull(logs);
- assertEquals(60, logs.length);
-
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?properties=asdf");
- ITUtil.assertResponseLength2CodeOKContent(response, ITUtil.EMPTY_JSON);
-
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?properties=a");
- ITUtil.assertResponseLength2CodeOKContent(response, ITUtil.EMPTY_JSON);
-
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?properties=A");
- ITUtil.assertResponseLength2CodeOK(response);
- logs = mapper.readValue(response[1], Log[].class);
- assertNotNull(logs);
- assertEquals(20, logs.length);
-
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?properties=B");
- ITUtil.assertResponseLength2CodeOKContent(response, ITUtil.EMPTY_JSON);
-
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?properties=C");
- ITUtil.assertResponseLength2CodeOKContent(response, ITUtil.EMPTY_JSON);
-
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?properties=Shift Info C");
- ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_VERSION);
-
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?properties='Shift Info C'");
- ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_VERSION);
-
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?properties="+URLEncoder.encode("Shift Info C", StandardCharsets.UTF_8));
- ITUtil.assertResponseLength2CodeOK(response);
- logs = mapper.readValue(response[1], Log[].class);
- assertNotNull(logs);
- assertEquals(20, logs.length);
-
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?properties='"+URLEncoder.encode("Shift Info C", StandardCharsets.UTF_8)+"'");
- ITUtil.assertResponseLength2CodeOKContent(response, ITUtil.EMPTY_JSON);
-
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?properties=.operator");
- ITUtil.assertResponseLength2CodeOKContent(response, ITUtil.EMPTY_JSON);
-
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?properties=.Operator");
- ITUtil.assertResponseLength2CodeOK(response);
- logs = mapper.readValue(response[1], Log[].class);
- assertNotNull(logs);
- assertEquals(60, logs.length);
-
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?properties=..12345678c");
- ITUtil.assertResponseLength2CodeOKContent(response, ITUtil.EMPTY_JSON);
-
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?properties=..12345678C");
- ITUtil.assertResponseLength2CodeOK(response);
- logs = mapper.readValue(response[1], Log[].class);
- assertNotNull(logs);
- assertEquals(20, logs.length);
-
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?properties=..*C");
- ITUtil.assertResponseLength2CodeOK(response);
- logs = mapper.readValue(response[1], Log[].class);
- assertNotNull(logs);
- assertEquals(20, logs.length);
-
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?properties=..12345678?");
- ITUtil.assertResponseLength2CodeOK(response);
- logs = mapper.readValue(response[1], Log[].class);
- assertNotNull(logs);
- assertEquals(60, logs.length);
-
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?properties=..12345*");
- ITUtil.assertResponseLength2CodeOK(response);
- logs = mapper.readValue(response[1], Log[].class);
- assertNotNull(logs);
- assertEquals(60, logs.length);
-
- // time
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?start");
- ITUtil.assertResponseLength2CodeOKContent(response, ITUtil.EMPTY_JSON);
-
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?start=asdf");
- ITUtil.assertResponseLength2CodeOK(response);
- logs = mapper.readValue(response[1], Log[].class);
- assertNotNull(logs);
- assertEquals(60, logs.length);
-
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?end");
- ITUtil.assertResponseLength2CodeOK(response);
- logs = mapper.readValue(response[1], Log[].class);
- assertNotNull(logs);
- assertEquals(60, logs.length);
-
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?end=asdf");
- ITUtil.assertResponseLength2CodeOKContent(response, ITUtil.EMPTY_JSON);
+ // intended and unintended usage, positive and negative tests
+ ITUtilLogs.assertListLogs("?properties", 60);
+ ITUtilLogs.assertListLogs("?properties=", 60);
+ ITUtilLogs.assertListLogs("?properties=asdf", 0);
+ ITUtilLogs.assertListLogs("?properties=a", 20);
+ ITUtilLogs.assertListLogs("?properties=A", 20);
+ ITUtilLogs.assertListLogs("?properties=B", 0);
+ ITUtilLogs.assertListLogs("?properties=C", 0);
+ ITUtilLogs.assertListLogs("?properties=Shift Info C", HttpURLConnection.HTTP_BAD_REQUEST, -1, -1);
+ ITUtilLogs.assertListLogs("?properties='Shift Info C'", HttpURLConnection.HTTP_BAD_REQUEST, -1, -1);
+ ITUtilLogs.assertListLogs("?properties=" + URLEncoder.encode("Shift Info C", StandardCharsets.UTF_8), 20);
+ ITUtilLogs.assertListLogs("?properties='" + URLEncoder.encode("Shift Info C", StandardCharsets.UTF_8) + "'", 0);
+ ITUtilLogs.assertListLogs("?properties=.operator", 60);
+ ITUtilLogs.assertListLogs("?properties=.Operator", 60);
+ ITUtilLogs.assertListLogs("?properties=..12345678c", 60);
+ ITUtilLogs.assertListLogs("?properties=..12345678C", 60);
+ ITUtilLogs.assertListLogs("?properties=..*C", 60);
+ ITUtilLogs.assertListLogs("?properties=..12345678?", 60);
+ ITUtilLogs.assertListLogs("?properties=..12345*", 60);
+
+ ITUtilLogs.assertListLogs("?properties=" + URLEncoder.encode("Info B", StandardCharsets.UTF_8), 20);
+ ITUtilLogs.assertListLogs("?properties=" + URLEncoder.encode("Info B", StandardCharsets.UTF_8) + "&properties=" + URLEncoder.encode("Shift Lead", StandardCharsets.UTF_8), 20);
+ ITUtilLogs.assertListLogs("?properties=" + URLEncoder.encode("Info B", StandardCharsets.UTF_8) + "&properties=" + URLEncoder.encode("Shift Lead", StandardCharsets.UTF_8) + "&properties=" + URLEncoder.encode("Maya Kobayashi", StandardCharsets.UTF_8), 20);
+ ITUtilLogs.assertListLogs("?properties=" + URLEncoder.encode("Info B", StandardCharsets.UTF_8) + "&properties=" + URLEncoder.encode("Shift Lead", StandardCharsets.UTF_8) + "&properties=" + URLEncoder.encode("Karl Svensson", StandardCharsets.UTF_8), 20);
+ ITUtilLogs.assertListLogs("?properties=" + URLEncoder.encode("Info B", StandardCharsets.UTF_8) + "." + URLEncoder.encode("Shift Lead", StandardCharsets.UTF_8), 20);
+ ITUtilLogs.assertListLogs("?properties=" + URLEncoder.encode("Info B", StandardCharsets.UTF_8) + "." + URLEncoder.encode("Shift Lead", StandardCharsets.UTF_8) + "." + URLEncoder.encode("Maya Kobayashi", StandardCharsets.UTF_8), 20);
+ ITUtilLogs.assertListLogs("?properties=" + URLEncoder.encode("Info B", StandardCharsets.UTF_8) + "." + URLEncoder.encode("Shift Lead", StandardCharsets.UTF_8) + "." + URLEncoder.encode("Karl Svensson", StandardCharsets.UTF_8), 0);
+ ITUtilLogs.assertListLogs("?properties=" + URLEncoder.encode("Info B.", StandardCharsets.UTF_8), 20);
+ ITUtilLogs.assertListLogs("?properties=" + URLEncoder.encode("Info B. ", StandardCharsets.UTF_8), 0);
+ ITUtilLogs.assertListLogs("?properties=" + URLEncoder.encode("Info B.Shift Lead", StandardCharsets.UTF_8), 20);
+ ITUtilLogs.assertListLogs("?properties=" + URLEncoder.encode("Info B.Shift Lead.", StandardCharsets.UTF_8), 20);
+ ITUtilLogs.assertListLogs("?properties=" + URLEncoder.encode("Info B.Shift Lead. ", StandardCharsets.UTF_8), 0);
+ ITUtilLogs.assertListLogs("?properties=" + URLEncoder.encode("Info B.Shift Lead.Maya Kobayashi", StandardCharsets.UTF_8), 20);
+ ITUtilLogs.assertListLogs("?properties=" + URLEncoder.encode("Info B.Shift Lead.Karl Svensson", StandardCharsets.UTF_8), 0);
+
+ ITUtilLogs.assertSearchLogs("?properties", 60);
+ ITUtilLogs.assertSearchLogs("?properties=", 60);
+ ITUtilLogs.assertSearchLogs("?properties=asdf", 0);
+ ITUtilLogs.assertSearchLogs("?properties=a", 20);
+ ITUtilLogs.assertSearchLogs("?properties=A", 20);
+ ITUtilLogs.assertSearchLogs("?properties=B", 0);
+ ITUtilLogs.assertSearchLogs("?properties=C", 0);
+ ITUtilLogs.assertSearchLogs("?properties=Shift Info C", HttpURLConnection.HTTP_BAD_REQUEST, -1, -1);
+ ITUtilLogs.assertSearchLogs("?properties='Shift Info C'", HttpURLConnection.HTTP_BAD_REQUEST, -1, -1);
+ ITUtilLogs.assertSearchLogs("?properties=" + URLEncoder.encode("Shift Info C", StandardCharsets.UTF_8), 20);
+ ITUtilLogs.assertSearchLogs("?properties='" + URLEncoder.encode("Shift Info C", StandardCharsets.UTF_8) + "'", 0);
+ ITUtilLogs.assertSearchLogs("?properties=.operator", 60);
+ ITUtilLogs.assertSearchLogs("?properties=.Operator", 60);
+ ITUtilLogs.assertSearchLogs("?properties=..12345678c", 60);
+ ITUtilLogs.assertSearchLogs("?properties=..12345678C", 60);
+ ITUtilLogs.assertSearchLogs("?properties=..*C", 60);
+ ITUtilLogs.assertSearchLogs("?properties=..12345678?", 60);
+ ITUtilLogs.assertSearchLogs("?properties=..12345*", 60);
+
+ ITUtilLogs.assertSearchLogs("?properties=" + URLEncoder.encode("Info B", StandardCharsets.UTF_8), 20);
+ ITUtilLogs.assertSearchLogs("?properties=" + URLEncoder.encode("Info B", StandardCharsets.UTF_8) + "&properties=" + URLEncoder.encode("Shift Lead", StandardCharsets.UTF_8), 20);
+ ITUtilLogs.assertSearchLogs("?properties=" + URLEncoder.encode("Info B", StandardCharsets.UTF_8) + "&properties=" + URLEncoder.encode("Shift Lead", StandardCharsets.UTF_8) + "&properties=" + URLEncoder.encode("Maya Kobayashi", StandardCharsets.UTF_8), 20);
+ ITUtilLogs.assertSearchLogs("?properties=" + URLEncoder.encode("Info B", StandardCharsets.UTF_8) + "&properties=" + URLEncoder.encode("Shift Lead", StandardCharsets.UTF_8) + "&properties=" + URLEncoder.encode("Karl Svensson", StandardCharsets.UTF_8), 20);
+ ITUtilLogs.assertSearchLogs("?properties=" + URLEncoder.encode("Info B", StandardCharsets.UTF_8) + "." + URLEncoder.encode("Shift Lead", StandardCharsets.UTF_8), 20);
+ ITUtilLogs.assertSearchLogs("?properties=" + URLEncoder.encode("Info B", StandardCharsets.UTF_8) + "." + URLEncoder.encode("Shift Lead", StandardCharsets.UTF_8) + "." + URLEncoder.encode("Maya Kobayashi", StandardCharsets.UTF_8), 20);
+ ITUtilLogs.assertSearchLogs("?properties=" + URLEncoder.encode("Info B", StandardCharsets.UTF_8) + "." + URLEncoder.encode("Shift Lead", StandardCharsets.UTF_8) + "." + URLEncoder.encode("Karl Svensson", StandardCharsets.UTF_8), 0);
+ ITUtilLogs.assertSearchLogs("?properties=" + URLEncoder.encode("Info B.", StandardCharsets.UTF_8), 20);
+ ITUtilLogs.assertSearchLogs("?properties=" + URLEncoder.encode("Info B. ", StandardCharsets.UTF_8), 0);
+ ITUtilLogs.assertSearchLogs("?properties=" + URLEncoder.encode("Info B.Shift Lead", StandardCharsets.UTF_8), 20);
+ ITUtilLogs.assertSearchLogs("?properties=" + URLEncoder.encode("Info B.Shift Lead.", StandardCharsets.UTF_8), 20);
+ ITUtilLogs.assertSearchLogs("?properties=" + URLEncoder.encode("Info B.Shift Lead. ", StandardCharsets.UTF_8), 0);
+ ITUtilLogs.assertSearchLogs("?properties=" + URLEncoder.encode("Info B.Shift Lead.Maya Kobayashi", StandardCharsets.UTF_8), 20);
+ ITUtilLogs.assertSearchLogs("?properties=" + URLEncoder.encode("Info B.Shift Lead.Karl Svensson", StandardCharsets.UTF_8), 0);
+
+ // ----------------------------------------------------------------------------------------------------
+
+ // level
+ ITUtilLogs.assertListLogs("?level", 0);
+ ITUtilLogs.assertListLogs("?level=", 0);
+ ITUtilLogs.assertListLogs("?level=asdf", 0);
+ ITUtilLogs.assertListLogs("?level=shift", 60);
+ ITUtilLogs.assertListLogs("?level=Shift", 60);
+ ITUtilLogs.assertListLogs("?level=update", 54);
+ ITUtilLogs.assertListLogs("?level=Update", 54);
+ ITUtilLogs.assertListLogs("?level=shift&level=update", 60);
+ ITUtilLogs.assertListLogs("?level=shift update", HttpURLConnection.HTTP_BAD_REQUEST, -1, -1);
+ ITUtilLogs.assertListLogs("?level='shift update'", HttpURLConnection.HTTP_BAD_REQUEST, -1, -1);
+ ITUtilLogs.assertListLogs("?level=" + URLEncoder.encode("shift update", StandardCharsets.UTF_8), 60);
+ ITUtilLogs.assertListLogs("?level='" + URLEncoder.encode("shift update", StandardCharsets.UTF_8) + "'", 0);
+ ITUtilLogs.assertListLogs("?level=" + URLEncoder.encode("SHIFT UPDATE", StandardCharsets.UTF_8), 60);
+ ITUtilLogs.assertListLogs("?level='" + URLEncoder.encode("SHIFT UPDATE", StandardCharsets.UTF_8) + "'", 0);
+ ITUtilLogs.assertListLogs("?level=?pdate", 54);
+ ITUtilLogs.assertListLogs("?level=upd??e", 54);
+ ITUtilLogs.assertListLogs("?level=*ate", 54);
+
+ ITUtilLogs.assertSearchLogs("?level", 0);
+ ITUtilLogs.assertSearchLogs("?level=", 0);
+ ITUtilLogs.assertSearchLogs("?level=asdf", 0);
+ ITUtilLogs.assertSearchLogs("?level=shift", 60);
+ ITUtilLogs.assertSearchLogs("?level=Shift", 60);
+ ITUtilLogs.assertSearchLogs("?level=update", 54);
+ ITUtilLogs.assertSearchLogs("?level=Update", 54);
+ ITUtilLogs.assertSearchLogs("?level=shift&level=update", 60);
+ ITUtilLogs.assertSearchLogs("?level=shift update", HttpURLConnection.HTTP_BAD_REQUEST, -1, -1);
+ ITUtilLogs.assertSearchLogs("?level='shift update'", HttpURLConnection.HTTP_BAD_REQUEST, -1, -1);
+ ITUtilLogs.assertSearchLogs("?level=" + URLEncoder.encode("shift update", StandardCharsets.UTF_8), 60);
+ ITUtilLogs.assertSearchLogs("?level='" + URLEncoder.encode("shift update", StandardCharsets.UTF_8) + "'", 0);
+ ITUtilLogs.assertSearchLogs("?level=" + URLEncoder.encode("SHIFT UPDATE", StandardCharsets.UTF_8), 60);
+ ITUtilLogs.assertSearchLogs("?level='" + URLEncoder.encode("SHIFT UPDATE", StandardCharsets.UTF_8) + "'", 0);
+ ITUtilLogs.assertSearchLogs("?level=?pdate", 54);
+ ITUtilLogs.assertSearchLogs("?level=upd??e", 54);
+ ITUtilLogs.assertSearchLogs("?level=*ate", 54);
+
+ // ----------------------------------------------------------------------------------------------------
+
+ // size, limit
+ // from
+ // sort
+ ITUtilLogs.assertListLogs("?size", 60);
+ ITUtilLogs.assertListLogs("?size=", 60);
+ ITUtilLogs.assertListLogs("?title=Shift&size=20", 20);
+
+ ITUtilLogs.assertListLogs("?from", 60);
+ ITUtilLogs.assertListLogs("?from=", 60);
+ ITUtilLogs.assertListLogs("?title=Shift&from=20", 23);
+
+ ITUtilLogs.assertListLogs("?sort", 60);
+ ITUtilLogs.assertListLogs("?sort=", 60);
+ ITUtilLogs.assertListLogs("?title=Shift&sort=ASC", 43);
+ ITUtilLogs.assertListLogs("?title=Shift&sort=UP", 43);
+ ITUtilLogs.assertListLogs("?title=Shift&sort=DESC", 43);
+ ITUtilLogs.assertListLogs("?title=Shift&sort=DOWN", 43);
+ ITUtilLogs.assertListLogs("?title=Shift&sort=asdf", 43);
+
+ ITUtilLogs.assertSearchLogs("?size", 60);
+ ITUtilLogs.assertSearchLogs("?size=", 60);
+ searchResult = ITUtilLogs.assertSearchLogs("?title=Shift&size=20", 43);
+ assertEquals(20, searchResult.getLogs().size());
+
+ ITUtilLogs.assertSearchLogs("?from", 60);
+ ITUtilLogs.assertSearchLogs("?from=", 60);
+ searchResult = ITUtilLogs.assertSearchLogs("?title=Shift&from=20", 43);
+ assertEquals(23, searchResult.getLogs().size());
+
+ ITUtilLogs.assertSearchLogs("?sort", 60);
+ ITUtilLogs.assertSearchLogs("?sort=", 60);
+ ITUtilLogs.assertSearchLogs("?title=Shift&sort=ASC", 43);
+ ITUtilLogs.assertSearchLogs("?title=Shift&sort=UP", 43);
+ ITUtilLogs.assertSearchLogs("?title=Shift&sort=DESC", 43);
+ ITUtilLogs.assertSearchLogs("?title=Shift&sort=DOWN", 43);
+ ITUtilLogs.assertSearchLogs("?title=Shift&sort=asdf", 43);
+
+ // ----------------------------------------------------------------------------------------------------
+
+ // attachments
+ ITUtilLogs.assertListLogs("?attachments", 0);
+ ITUtilLogs.assertListLogs("?attachments=", 0);
+ ITUtilLogs.assertListLogs("?attachments=asdf", 0);
+
+ ITUtilLogs.assertSearchLogs("?attachments", 0);
+ ITUtilLogs.assertSearchLogs("?attachments=", 0);
+ ITUtilLogs.assertSearchLogs("?attachments=asdf", 0);
+
+ // ----------------------------------------------------------------------------------------------------
+ // keyword combinations
+ // ----------------------------------------------------------------------------------------------------
// default
// unsupported search parameters are ignored
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?zxcv");
- ITUtil.assertResponseLength2CodeOK(response);
- logs = mapper.readValue(response[1], Log[].class);
- assertNotNull(logs);
- assertEquals(60, logs.length);
-
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?zxcv=asdf");
- ITUtil.assertResponseLength2CodeOK(response);
- logs = mapper.readValue(response[1], Log[].class);
- assertNotNull(logs);
- assertEquals(60, logs.length);
+ ITUtilLogs.assertListLogs("?zxcv", 60);
+ ITUtilLogs.assertListLogs("?zxcv=asdf", 60);
+
+ ITUtilLogs.assertSearchLogs("?zxcv", 60);
+ ITUtilLogs.assertSearchLogs("?zxcv=asdf", 60);
// combinations
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?logbooks=*&description=maintenance");
- ITUtil.assertResponseLength2CodeOK(response);
- logs = mapper.readValue(response[1], Log[].class);
- assertNotNull(logs);
- assertEquals(2, logs.length);
-
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?tags=*&description=maintenance");
- ITUtil.assertResponseLength2CodeOK(response);
- logs = mapper.readValue(response[1], Log[].class);
- assertNotNull(logs);
- assertEquals(1, logs.length);
-
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?properties=..12345678A&phrase="+URLEncoder.encode("Start-up after maintenance", StandardCharsets.UTF_8));
- ITUtil.assertResponseLength2CodeOKContent(response, ITUtil.EMPTY_JSON);
-
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?properties=..12345678C&phrase="+URLEncoder.encode("Start-up after maintenance", StandardCharsets.UTF_8));
- // expected 3
- ITUtil.assertResponseLength2CodeOKContent(response, ITUtil.EMPTY_JSON);
-
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?properties=..123*&phrase="+URLEncoder.encode("Start-up after maintenance", StandardCharsets.UTF_8));
- // expected 3
- ITUtil.assertResponseLength2CodeOKContent(response, ITUtil.EMPTY_JSON);
-
- response = ITUtil.doGetJson(OlogLogsQueryIT.HTTP_IP_PORT_OLOG_LOGS + "?properties=..123*&description=maintenance");
- ITUtil.assertResponseLength2CodeOK(response);
- logs = mapper.readValue(response[1], Log[].class);
- assertNotNull(logs);
- assertEquals(2, logs.length);
- } catch (IOException e) {
- fail();
+ ITUtilLogs.assertListLogs("?logbooks=*&description=maintenance", 17);
+ ITUtilLogs.assertListLogs("?tags=*&description=maintenance", 12);
+ ITUtilLogs.assertListLogs("?properties=..123*&description=maintenance", 17);
+ ITUtilLogs.assertListLogs("?properties=..12345678A&phrase=" + URLEncoder.encode("Start-up after maintenance", StandardCharsets.UTF_8), 3);
+ ITUtilLogs.assertListLogs("?properties=..12345678C&phrase=" + URLEncoder.encode("Start-up after maintenance", StandardCharsets.UTF_8), 3);
+ ITUtilLogs.assertListLogs("?properties=..123*&phrase=" + URLEncoder.encode("Start-up after maintenance", StandardCharsets.UTF_8), 3);
+
+ ITUtilLogs.assertSearchLogs("?logbooks=*&description=maintenance", 17);
+ ITUtilLogs.assertSearchLogs("?tags=*&description=maintenance", 12);
+ ITUtilLogs.assertSearchLogs("?properties=..123*&description=maintenance", 17);
+ ITUtilLogs.assertSearchLogs("?properties=..12345678A&phrase=" + URLEncoder.encode("Start-up after maintenance", StandardCharsets.UTF_8), 3);
+ ITUtilLogs.assertSearchLogs("?properties=..12345678C&phrase=" + URLEncoder.encode("Start-up after maintenance", StandardCharsets.UTF_8), 3);
+ ITUtilLogs.assertSearchLogs("?properties=..123*&phrase=" + URLEncoder.encode("Start-up after maintenance", StandardCharsets.UTF_8), 3);
} catch (Exception e) {
fail();
}
diff --git a/src/test/java/org/phoebus/olog/docker/OlogPropertiesIT.java b/src/test/java/org/phoebus/olog/docker/OlogPropertiesIT.java
index be3391b..0e6bc7b 100644
--- a/src/test/java/org/phoebus/olog/docker/OlogPropertiesIT.java
+++ b/src/test/java/org/phoebus/olog/docker/OlogPropertiesIT.java
@@ -1,28 +1,39 @@
/*
* Copyright (C) 2021 European Spallation Source ERIC.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
package org.phoebus.olog.docker;
-import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
+import org.phoebus.olog.docker.ITUtil.AuthorizationChoice;
import org.phoebus.olog.entity.Attribute;
import org.phoebus.olog.entity.Property;
import org.phoebus.olog.entity.State;
-import org.testcontainers.containers.DockerComposeContainer;
-import org.testcontainers.containers.wait.strategy.Wait;
+import org.testcontainers.containers.ComposeContainer;
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;
-import java.io.File;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.util.HashSet;
import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
/**
@@ -38,7 +49,7 @@
* @see org.phoebus.olog.PropertiesResource
*/
@Testcontainers
-public class OlogPropertiesIT {
+class OlogPropertiesIT {
// Note
// ------------------------------------------------------------------------------------------------
@@ -59,25 +70,21 @@ public class OlogPropertiesIT {
// Olog - Service Documentation
// https://olog.readthedocs.io/en/latest/
// ------------------------------------------------------------------------------------------------
- // OLOG API PropertiesResource
- // -------------------- --------------------
- // Retrieve a Property .../properties/ (GET) findByTitle(String)
- // List Properties .../properties (GET) findAll(boolean)
- // Create a Property .../properties/ (PUT) createProperty(String, Property, Principal)
- // Create Properties .../properties (PUT) updateProperty(List)
- // Remove Property .../properties/ (DELETE) deleteProperty(String)
+ // OLOG API PropertiesResource
+ // -------------------- --------------------
+ // Retrieve a Property .../properties/ (GET) findByTitle(String)
+ // List Properties .../properties (GET) findAll(boolean)
+ // Create a Property .../properties/ (PUT) createProperty(String, Property, Principal)
+ // Create Properties .../properties (PUT) updateProperty(List)
+ // Remove Property .../properties/ (DELETE) deleteProperty(String)
// ------------------------------------------------------------------------------------------------
- static final String PROPERTIES = "/properties";
-
- static final String HTTP_IP_PORT_OLOG_PROPERTIES = ITUtil.HTTP + ITUtil.IP_PORT_OLOG + PROPERTIES;
- static final String HTTP_AUTH_USER_IP_PORT_OLOG_PROPERTIES = ITUtil.HTTP + ITUtil.AUTH_USER + "@" + ITUtil.IP_PORT_OLOG + PROPERTIES;
- static final String HTTP_AUTH_ADMIN_IP_PORT_OLOG_PROPERTIES = ITUtil.HTTP + ITUtil.AUTH_ADMIN + "@" + ITUtil.IP_PORT_OLOG + PROPERTIES;
-
// test data
// properties p1 - p10, owner admin, state Active - Inactive
// properties p1 - p2, owner admin, state Inactive
+ static Property[] default_properties;
+
static Attribute a1;
static Attribute a2;
static Attribute a3;
@@ -102,12 +109,14 @@ public class OlogPropertiesIT {
static Property property_p10_owner_a_state_i_attributes;
@Container
- public static final DockerComposeContainer> ENVIRONMENT =
- new DockerComposeContainer<>(new File("docker-compose.yml"))
- .waitingFor(ITUtil.OLOG, Wait.forLogMessage(".*Started Application.*", 1));
+ public static final ComposeContainer ENVIRONMENT = ITUtil.defaultComposeContainers();
@BeforeAll
public static void setupObjects() {
+ default_properties = new Property[] {new Property("resource", null, State.Active, new HashSet())};
+ default_properties[0].addAttributes(new Attribute("name", null, State.Active));
+ default_properties[0].addAttributes(new Attribute("file", null, State.Active));
+
a1 = new Attribute("a1", "v1", State.Active);
a2 = new Attribute("a2", "v2", State.Active);
a3 = new Attribute("a3", "v3", State.Active);
@@ -179,6 +188,8 @@ public static void setupObjects() {
@AfterAll
public static void tearDownObjects() {
+ default_properties = null;
+
property_p1_owner_a_state_a_attributes = null;
property_p2_owner_a_state_a_attributes = null;
property_p3_owner_a_state_a_attributes = null;
@@ -203,8 +214,15 @@ public static void tearDownObjects() {
a5 = null;
}
+ @AfterAll
+ public static void extractJacocoReport() {
+ // extract jacoco report from container file system
+ ITUtil.extractJacocoReport(ENVIRONMENT,
+ ITUtil.JACOCO_TARGET_PREFIX + OlogPropertiesIT.class.getSimpleName() + ITUtil.JACOCO_TARGET_SUFFIX);
+ }
+
@Test
- public void ologUp() {
+ void ologUp() {
try {
String address = ITUtil.HTTP_IP_PORT_OLOG;
int responseCode = ITUtil.doGet(address);
@@ -219,7 +237,7 @@ public void ologUp() {
* Test {@link org.phoebus.olog.OlogResourceDescriptors#PROPERTY_RESOURCE_URI}.
*/
@Test
- public void handlePropertyRetrieveCheck() {
+ void handlePropertyRetrieveCheck() {
// what
// check(s) for retrieve property
// e.g.
@@ -231,19 +249,14 @@ public void handlePropertyRetrieveCheck() {
// Create Properties
// Remove Property
- try {
- String[] response = ITUtil.doGetJson(HTTP_IP_PORT_OLOG_PROPERTIES + "/p11");
- ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_NOT_FOUND);
- } catch (IOException e) {
- fail();
- }
+ ITUtilProperties.assertRetrieveProperty("/p11", HttpURLConnection.HTTP_NOT_FOUND);
}
/**
* Test {@link org.phoebus.olog.OlogResourceDescriptors#PROPERTY_RESOURCE_URI}.
*/
@Test
- public void handlePropertyRemoveCheck() {
+ void handlePropertyRemoveCheck() {
// what
// check(s) for remove property
// e.g.
@@ -255,27 +268,21 @@ public void handlePropertyRemoveCheck() {
// Create Properties
// x Remove Property
- try {
- // might be both 401, 404
- // 401 UNAUTHORIZED
- // 404 NOT_FOUND
- String[] response = ITUtil.runShellCommand(deleteCurlPropertyForUser("p11"));
- ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_NOT_FOUND);
-
- response = ITUtil.runShellCommand(deleteCurlPropertyForAdmin("p11"));
- ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_NOT_FOUND);
- } catch (IOException e) {
- fail();
- } catch (Exception e) {
- fail();
- }
+ // might be both 401, 404
+ // 401 UNAUTHORIZED
+ // 404 NOT_FOUND
+
+ // check permissions
+
+ ITUtilProperties.assertRemoveProperty(AuthorizationChoice.USER, "/p11", HttpURLConnection.HTTP_NOT_FOUND);
+ ITUtilProperties.assertRemoveProperty(AuthorizationChoice.ADMIN, "/p11", HttpURLConnection.HTTP_NOT_FOUND);
}
/**
* Test {@link org.phoebus.olog.OlogResourceDescriptors#PROPERTY_RESOURCE_URI}.
*/
@Test
- public void handlePropertyCreateCheckJson() {
+ void handlePropertyCreateCheckJson() {
// what
// check(s) for create property
// e.g.
@@ -305,64 +312,31 @@ public void handlePropertyCreateCheckJson() {
String json_incomplete9 = "\"";
String json_property_p1_name_na = "{\"na\":\"p1\",\"owner\":\"admin\",\"state\":\"Active\",\"attributes\":[]}";
-
String json_property_p1_attribute_0 = "{\"name\":\"p1\",\"owner\":\"admin\",\"state\":\"Active\",\"attributes\":[\"name\":\"a1\",\"value\":\"v1\",\"state\":\"Active\"]}";
-
String json_property_p1_attribute_2_state_hyperactive = "{\"name\":\"p1\",\"owner\":\"admin\",\"state\":\"Active\",\"attributes\":[{\"name\":\"a1\",\"value\":\"v1\",\"state\":\"Active\"},{\"name\":\"a1\",\"value\":\"v1\",\"state\":\"Hyperactive\"}]}";
- try {
- String[] response = ITUtil.doGetJson(HTTP_IP_PORT_OLOG_PROPERTIES);
- ITUtil.assertResponseLength2CodeOKContent(response, ITUtil.EMPTY_JSON);
-
- response = ITUtil.runShellCommand(createCurlPropertyForAdmin("p1", json_incomplete1));
- ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_BAD_REQUEST);
-
- response = ITUtil.runShellCommand(createCurlPropertyForAdmin("p1", json_incomplete2));
- ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_BAD_REQUEST);
-
- response = ITUtil.runShellCommand(createCurlPropertyForAdmin("p1", json_incomplete3));
- ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_BAD_REQUEST);
-
- response = ITUtil.runShellCommand(createCurlPropertyForAdmin("p1", json_incomplete4));
- ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_BAD_REQUEST);
-
- response = ITUtil.runShellCommand(createCurlPropertyForAdmin("p1", json_incomplete5));
- ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_BAD_REQUEST);
-
- response = ITUtil.runShellCommand(createCurlPropertyForAdmin("p1", json_incomplete7));
- ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_BAD_REQUEST);
-
- response = ITUtil.runShellCommand(createCurlPropertyForAdmin("p1", json_incomplete8));
- ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_BAD_REQUEST);
-
- response = ITUtil.runShellCommand(createCurlPropertyForAdmin("p1", json_incomplete9));
- ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_BAD_REQUEST);
-
- response = ITUtil.runShellCommand(createCurlPropertyForAdmin("p1", json_property_p1_name_na));
- ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_BAD_REQUEST);
-
- response = ITUtil.runShellCommand(createCurlPropertyForAdmin("p1", json_property_p1_attribute_0));
- ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_BAD_REQUEST);
-
- response = ITUtil.runShellCommand(createCurlPropertyForAdmin("p1", json_property_p1_attribute_2_state_hyperactive));
- ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_BAD_REQUEST);
-
- response = ITUtil.doGetJson(HTTP_IP_PORT_OLOG_PROPERTIES);
- ITUtil.assertResponseLength2CodeOKContent(response, ITUtil.EMPTY_JSON);
- } catch (IOException e) {
- fail();
- } catch (InterruptedException e) {
- fail();
- } catch (Exception e) {
- fail();
- }
+ ITUtilProperties.assertListProperties(1, default_properties[0]);
+
+ ITUtilProperties.assertCreateProperty(AuthorizationChoice.ADMIN, "/p1", json_incomplete1, HttpURLConnection.HTTP_BAD_REQUEST);
+ ITUtilProperties.assertCreateProperty(AuthorizationChoice.ADMIN, "/p1", json_incomplete2, HttpURLConnection.HTTP_BAD_REQUEST);
+ ITUtilProperties.assertCreateProperty(AuthorizationChoice.ADMIN, "/p1", json_incomplete3, HttpURLConnection.HTTP_BAD_REQUEST);
+ ITUtilProperties.assertCreateProperty(AuthorizationChoice.ADMIN, "/p1", json_incomplete4, HttpURLConnection.HTTP_BAD_REQUEST);
+ ITUtilProperties.assertCreateProperty(AuthorizationChoice.ADMIN, "/p1", json_incomplete5, HttpURLConnection.HTTP_BAD_REQUEST);
+ ITUtilProperties.assertCreateProperty(AuthorizationChoice.ADMIN, "/p1", json_incomplete7, HttpURLConnection.HTTP_BAD_REQUEST);
+ ITUtilProperties.assertCreateProperty(AuthorizationChoice.ADMIN, "/p1", json_incomplete8, HttpURLConnection.HTTP_BAD_REQUEST);
+ ITUtilProperties.assertCreateProperty(AuthorizationChoice.ADMIN, "/p1", json_incomplete9, HttpURLConnection.HTTP_BAD_REQUEST);
+ ITUtilProperties.assertCreateProperty(AuthorizationChoice.ADMIN, "/p1", json_property_p1_name_na, HttpURLConnection.HTTP_BAD_REQUEST);
+ ITUtilProperties.assertCreateProperty(AuthorizationChoice.ADMIN, "/p1", json_property_p1_attribute_0, HttpURLConnection.HTTP_BAD_REQUEST);
+ ITUtilProperties.assertCreateProperty(AuthorizationChoice.ADMIN, "/p1", json_property_p1_attribute_2_state_hyperactive, HttpURLConnection.HTTP_BAD_REQUEST);
+
+ ITUtilProperties.assertListProperties(1, default_properties[0]);
}
/**
* Test {@link org.phoebus.olog.OlogResourceDescriptors#PROPERTY_RESOURCE_URI}.
*/
@Test
- public void handlePropertyCreateCheck() {
+ void handlePropertyCreateCheck() {
// what
// check(s) for create property
// e.g.
@@ -385,78 +359,57 @@ public void handlePropertyCreateCheck() {
Property property_check = new Property();
Attribute attribute_check = new Attribute();
- ObjectMapper mapper = new ObjectMapper();
+ ITUtilProperties.assertListProperties(1, default_properties[0]);
- try {
- String[] response = ITUtil.doGetJson(HTTP_IP_PORT_OLOG_PROPERTIES);
- ITUtil.assertResponseLength2CodeOKContent(response, ITUtil.EMPTY_JSON);
-
- // response = ITUtil.runShellCommand(createCurlPropertyForUser("p1", mapper.writeValueAsString(property_p1_owner_a_state_a_attributes)));
- // ITUtil.assertResponseLength2Code(HttpURLConnection.HTTP_UNAUTHORIZED, response);
-
- response = ITUtil.runShellCommand(createCurlPropertyForUser("asdf", mapper.writeValueAsString(property_check)));
- ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_BAD_REQUEST);
+ // check permissions
+ // ITUtilProperties.assertCreateProperty(AuthorizationChoice.USER, "/p1", property_p1_owner_a_state_a_attributes, HttpURLConnection.HTTP_UNAUTHORIZED);
- response = ITUtil.runShellCommand(createCurlPropertyForAdmin("asdf", mapper.writeValueAsString(property_check)));
- ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_BAD_REQUEST);
+ ITUtilProperties.assertCreateProperty(AuthorizationChoice.USER, "/asdf", property_check, HttpURLConnection.HTTP_BAD_REQUEST);
+ ITUtilProperties.assertCreateProperty(AuthorizationChoice.ADMIN, "/asdf", property_check, HttpURLConnection.HTTP_BAD_REQUEST);
- property_check.setName(null);
+ property_check.setName(null);
- response = ITUtil.runShellCommand(createCurlPropertyForAdmin("asdf", mapper.writeValueAsString(property_check)));
- ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_BAD_REQUEST);
+ ITUtilProperties.assertCreateProperty(AuthorizationChoice.ADMIN, "/asdf", property_check, HttpURLConnection.HTTP_BAD_REQUEST);
- property_check.setName("");
+ property_check.setName("");
- response = ITUtil.runShellCommand(createCurlPropertyForAdmin("asdf", mapper.writeValueAsString(property_check)));
- ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_BAD_REQUEST);
+ ITUtilProperties.assertCreateProperty(AuthorizationChoice.ADMIN, "/asdf", property_check, HttpURLConnection.HTTP_BAD_REQUEST);
- property_check.setName("asdf");
- property_check.setOwner("zxcv");
- property_check.setState(State.Active);
- property_check.setAttributes(null);
+ property_check.setName("asdf");
+ property_check.setOwner("zxcv");
+ property_check.setState(State.Active);
+ property_check.setAttributes(null);
- response = ITUtil.runShellCommand(createCurlPropertyForAdmin("asdf", mapper.writeValueAsString(property_check)));
- ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_INTERNAL_ERROR);
+ ITUtilProperties.assertCreateProperty(AuthorizationChoice.ADMIN, "/asdf", property_check, HttpURLConnection.HTTP_INTERNAL_ERROR);
- property_check = new Property();
- property_check.setName("asdf");
- property_check.setOwner("zxcv");
- property_check.setState(State.Active);
- property_check.addAttributes(attribute_check);
+ property_check = new Property();
+ property_check.setName("asdf");
+ property_check.setOwner("zxcv");
+ property_check.setState(State.Active);
+ property_check.addAttributes(attribute_check);
- response = ITUtil.runShellCommand(createCurlPropertyForAdmin("asdf", mapper.writeValueAsString(property_check)));
- ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_BAD_REQUEST);
+ ITUtilProperties.assertCreateProperty(AuthorizationChoice.ADMIN, "/asdf", property_check, HttpURLConnection.HTTP_BAD_REQUEST);
- attribute_check.setName(null);
- property_check.getAttributes().clear();
- property_check.addAttributes(attribute_check);
+ attribute_check.setName(null);
+ property_check.getAttributes().clear();
+ property_check.addAttributes(attribute_check);
- response = ITUtil.runShellCommand(createCurlPropertyForAdmin("asdf", mapper.writeValueAsString(property_check)));
- ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_BAD_REQUEST);
+ ITUtilProperties.assertCreateProperty(AuthorizationChoice.ADMIN, "/asdf", property_check, HttpURLConnection.HTTP_BAD_REQUEST);
- attribute_check.setName("");
- property_check.getAttributes().clear();
- property_check.addAttributes(attribute_check);
+ attribute_check.setName("");
+ property_check.getAttributes().clear();
+ property_check.addAttributes(attribute_check);
- response = ITUtil.runShellCommand(createCurlPropertyForAdmin("asdf", mapper.writeValueAsString(property_check)));
- ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_BAD_REQUEST);
+ ITUtilProperties.assertCreateProperty(AuthorizationChoice.ADMIN, "/asdf", property_check, HttpURLConnection.HTTP_BAD_REQUEST);
- response = ITUtil.doGetJson(HTTP_IP_PORT_OLOG_PROPERTIES);
- ITUtil.assertResponseLength2CodeOKContent(response, ITUtil.EMPTY_JSON);
- } catch (IOException e) {
- fail();
- } catch (InterruptedException e) {
- fail();
- } catch (Exception e) {
- fail();
- }
+ ITUtilProperties.assertListProperties(1, default_properties[0]);
}
/**
* Test {@link org.phoebus.olog.OlogResourceDescriptors#PROPERTY_RESOURCE_URI}.
*/
@Test
- public void handleProperty() {
+ void handleProperty() {
// what
// user with required role
// create property
@@ -469,69 +422,48 @@ public void handleProperty() {
// Create Properties
// x Remove Property
- ObjectMapper mapper = new ObjectMapper();
-
try {
- String[] response = ITUtil.doGetJson(HTTP_IP_PORT_OLOG_PROPERTIES);
- ITUtil.assertResponseLength2CodeOKContent(response, ITUtil.EMPTY_JSON);
+ ITUtilProperties.assertListProperties(1, default_properties[0]);
+
+ ITUtilProperties.assertCreateProperty("/p1", property_p1_owner_a_state_a_attributes);
- response = ITUtil.runShellCommand(createCurlPropertyForAdmin("p1", mapper.writeValueAsString(property_p1_owner_a_state_a_attributes)));
- ITUtil.assertResponseLength2CodeOK(response);
- assertTrue(property_p1_owner_a_state_a_attributes.equals(mapper.readValue(response[1], Property.class)));
+ // refresh elastic indices
+ ITUtil.assertRefreshElasticIndices();
+
+ ITUtilProperties.assertListProperties(2,
+ property_p1_owner_a_state_a_attributes,
+ default_properties[0]);
+
+ ITUtilProperties.assertListProperties("?inactive=false", 2,
+ property_p1_owner_a_state_a_attributes,
+ default_properties[0]);
+
+ ITUtilProperties.assertListProperties("?inactive=true", 2,
+ property_p1_owner_a_state_a_attributes,
+ default_properties[0]);
+
+ ITUtilProperties.assertRetrieveProperty("/p1", property_p1_owner_a_state_a_attributes);
+
+ // check permissions
+ // ITUtilProperties.assertRemoveProperty(AuthorizationChoice.USER, "/p1", HttpURLConnection.HTTP_UNAUTHORIZED);
+
+ ITUtilProperties.assertRemoveProperty("/p1");
// refresh elastic indices
- response = ITUtil.refreshElasticIndices();
- ITUtil.assertResponseLength2CodeOK(response);
-
- response = ITUtil.doGetJson(HTTP_IP_PORT_OLOG_PROPERTIES);
- ITUtil.assertResponseLength2CodeOK(response);
- ITUtil.assertEqualsProperties(
- mapper.readValue(response[1], Property[].class),
- property_p1_owner_a_state_a_attributes);
-
- response = ITUtil.doGetJson(HTTP_IP_PORT_OLOG_PROPERTIES + "?inactive=false");
- ITUtil.assertResponseLength2CodeOK(response);
- ITUtil.assertEqualsProperties(
- mapper.readValue(response[1], Property[].class),
- property_p1_owner_a_state_a_attributes);
-
- response = ITUtil.doGetJson(HTTP_IP_PORT_OLOG_PROPERTIES + "?inactive=true");
- ITUtil.assertResponseLength2CodeOK(response);
- ITUtil.assertEqualsProperties(
- mapper.readValue(response[1], Property[].class),
- property_p1_owner_a_state_a_attributes);
-
- response = ITUtil.doGetJson(HTTP_IP_PORT_OLOG_PROPERTIES + "/p1");
- ITUtil.assertResponseLength2CodeOK(response);
- assertTrue(property_p1_owner_a_state_a_attributes.equals(mapper.readValue(response[1], Property.class)));
-
- // response = ITUtil.runShellCommand(deleteCurlPropertyForUser("p1"));
- // ITUtil.assertResponseLength2Code(HttpURLConnection.HTTP_UNAUTHORIZED, response);
-
- response = ITUtil.runShellCommand(deleteCurlPropertyForAdmin("p1"));
- ITUtil.assertResponseLength2CodeOK(response);
-
- response = ITUtil.doGetJson(HTTP_IP_PORT_OLOG_PROPERTIES + "/p1");
- ITUtil.assertResponseLength2CodeOK(response);
- assertTrue(property_p1_owner_a_state_i_attributes.equals(mapper.readValue(response[1], Property.class)));
-
- response = ITUtil.doGetJson(HTTP_IP_PORT_OLOG_PROPERTIES + "?inactive=false");
- ITUtil.assertResponseLength2CodeOK(response);
- ITUtil.assertEqualsProperties(
- mapper.readValue(response[1], Property[].class));
-
- response = ITUtil.doGetJson(HTTP_IP_PORT_OLOG_PROPERTIES + "?inactive=true");
- ITUtil.assertResponseLength2CodeOK(response);
- ITUtil.assertEqualsProperties(
- mapper.readValue(response[1], Property[].class),
- property_p1_owner_a_state_i_attributes);
-
- response = ITUtil.doGetJson(HTTP_IP_PORT_OLOG_PROPERTIES);
- ITUtil.assertResponseLength2CodeOKContent(response, ITUtil.EMPTY_JSON);
+ ITUtil.assertRefreshElasticIndices();
+
+ ITUtilProperties.assertRetrieveProperty("/p1", property_p1_owner_a_state_i_attributes);
+
+ ITUtilProperties.assertListProperties("?inactive=false", 1,
+ default_properties[0]);
+
+ ITUtilProperties.assertListProperties("?inactive=true", 2,
+ property_p1_owner_a_state_i_attributes,
+ default_properties[0]);
+
+ ITUtilProperties.assertListProperties(1, default_properties[0]);
} catch (IOException e) {
fail();
- } catch (InterruptedException e) {
- fail();
} catch (Exception e) {
fail();
}
@@ -541,7 +473,7 @@ public void handleProperty() {
* Test {@link org.phoebus.olog.OlogResourceDescriptors#PROPERTY_RESOURCE_URI}.
*/
@Test
- public void handleProperty2() {
+ void handleProperty2() {
// what
// create properties, one by one
// --------------------------------------------------------------------------------
@@ -553,104 +485,71 @@ public void handleProperty2() {
// Create Properties
// x Remove Property
- ObjectMapper mapper = new ObjectMapper();
-
try {
- String[] response = ITUtil.doGetJson(HTTP_IP_PORT_OLOG_PROPERTIES);
- ITUtil.assertResponseLength2CodeOKContent(response, ITUtil.EMPTY_JSON);
+ ITUtilProperties.assertListProperties(1, default_properties[0]);
- response = ITUtil.runShellCommand(createCurlPropertyForAdmin("p1", mapper.writeValueAsString(property_p1_owner_a_state_a_attributes)));
- ITUtil.assertResponseLength2CodeOK(response);
- assertEquals(property_p1_owner_a_state_a_attributes, mapper.readValue(response[1], Property.class));
-
- response = ITUtil.runShellCommand(createCurlPropertyForAdmin("p2", mapper.writeValueAsString(property_p2_owner_a_state_a_attributes)));
- ITUtil.assertResponseLength2CodeOK(response);
- assertEquals(property_p2_owner_a_state_a_attributes, mapper.readValue(response[1], Property.class));
+ ITUtilProperties.assertCreateProperty("/p1", property_p1_owner_a_state_a_attributes);
+ ITUtilProperties.assertCreateProperty("/p2", property_p2_owner_a_state_a_attributes);
// refresh elastic indices
- response = ITUtil.refreshElasticIndices();
- ITUtil.assertResponseLength2CodeOK(response);
+ ITUtil.assertRefreshElasticIndices();
- response = ITUtil.doGetJson(HTTP_IP_PORT_OLOG_PROPERTIES);
- ITUtil.assertResponseLength2CodeOK(response);
- ITUtil.assertEqualsProperties(
- mapper.readValue(response[1], Property[].class),
+ ITUtilProperties.assertListProperties(3,
property_p1_owner_a_state_a_attributes,
- property_p2_owner_a_state_a_attributes);
+ property_p2_owner_a_state_a_attributes,
+ default_properties[0]);
- response = ITUtil.doGetJson(HTTP_IP_PORT_OLOG_PROPERTIES + "?inactive=false");
- ITUtil.assertResponseLength2CodeOK(response);
- ITUtil.assertEqualsProperties(
- mapper.readValue(response[1], Property[].class),
+ ITUtilProperties.assertListProperties("?inactive=false", 3,
property_p1_owner_a_state_a_attributes,
- property_p2_owner_a_state_a_attributes);
+ property_p2_owner_a_state_a_attributes,
+ default_properties[0]);
- response = ITUtil.doGetJson(HTTP_IP_PORT_OLOG_PROPERTIES + "?inactive=true");
- ITUtil.assertResponseLength2CodeOK(response);
- ITUtil.assertEqualsProperties(
- mapper.readValue(response[1], Property[].class),
+ ITUtilProperties.assertListProperties("?inactive=true", 3,
property_p1_owner_a_state_a_attributes,
- property_p2_owner_a_state_a_attributes);
-
- response = ITUtil.doGetJson(HTTP_IP_PORT_OLOG_PROPERTIES + "/p1");
- ITUtil.assertResponseLength2CodeOK(response);
- assertEquals(property_p1_owner_a_state_a_attributes, mapper.readValue(response[1], Property.class));
-
- response = ITUtil.doGetJson(HTTP_IP_PORT_OLOG_PROPERTIES + "/p2");
- ITUtil.assertResponseLength2CodeOK(response);
- assertEquals(property_p2_owner_a_state_a_attributes, mapper.readValue(response[1], Property.class));
-
- response = ITUtil.runShellCommand(deleteCurlPropertyForAdmin("p1"));
- ITUtil.assertResponseLength2CodeOK(response);
-
- response = ITUtil.doGetJson(HTTP_IP_PORT_OLOG_PROPERTIES);
- ITUtil.assertResponseLength2CodeOK(response);
- ITUtil.assertEqualsProperties(
- mapper.readValue(response[1], Property[].class),
- property_p2_owner_a_state_a_attributes);
-
- response = ITUtil.doGetJson(HTTP_IP_PORT_OLOG_PROPERTIES + "?inactive=false");
- ITUtil.assertResponseLength2CodeOK(response);
- ITUtil.assertEqualsProperties(
- mapper.readValue(response[1], Property[].class),
- property_p2_owner_a_state_a_attributes);
-
- response = ITUtil.doGetJson(HTTP_IP_PORT_OLOG_PROPERTIES + "?inactive=true");
- ITUtil.assertResponseLength2CodeOK(response);
- ITUtil.assertEqualsProperties(
- mapper.readValue(response[1], Property[].class),
+ property_p2_owner_a_state_a_attributes,
+ default_properties[0]);
+
+ ITUtilProperties.assertRetrieveProperty("/p1", property_p1_owner_a_state_a_attributes);
+ ITUtilProperties.assertRetrieveProperty("/p2", property_p2_owner_a_state_a_attributes);
+
+ ITUtilProperties.assertRemoveProperty("/p1");
+
+ // refresh elastic indices
+ ITUtil.assertRefreshElasticIndices();
+
+ ITUtilProperties.assertListProperties(2,
+ property_p2_owner_a_state_a_attributes,
+ default_properties[0]);
+
+ ITUtilProperties.assertListProperties("?inactive=false", 2,
+ property_p2_owner_a_state_a_attributes,
+ default_properties[0]);
+
+ ITUtilProperties.assertListProperties("?inactive=true", 3,
property_p1_owner_a_state_i_attributes,
- property_p2_owner_a_state_a_attributes);
+ property_p2_owner_a_state_a_attributes,
+ default_properties[0]);
- response = ITUtil.doGetJson(HTTP_IP_PORT_OLOG_PROPERTIES + "/p1");
- ITUtil.assertResponseLength2CodeOK(response);
- assertEquals(property_p1_owner_a_state_i_attributes, mapper.readValue(response[1], Property.class));
+ ITUtilProperties.assertRetrieveProperty("/p1", property_p1_owner_a_state_i_attributes);
- response = ITUtil.runShellCommand(deleteCurlPropertyForAdmin("p2"));
- ITUtil.assertResponseLength2CodeOK(response);
+ ITUtilProperties.assertRemoveProperty("/p2");
+
+ // refresh elastic indices
+ ITUtil.assertRefreshElasticIndices();
- response = ITUtil.doGetJson(HTTP_IP_PORT_OLOG_PROPERTIES + "/p2");
- ITUtil.assertResponseLength2CodeOK(response);
- assertEquals(property_p2_owner_a_state_i_attributes, mapper.readValue(response[1], Property.class));
+ ITUtilProperties.assertRetrieveProperty("/p2", property_p2_owner_a_state_i_attributes);
- response = ITUtil.doGetJson(HTTP_IP_PORT_OLOG_PROPERTIES + "?inactive=false");
- ITUtil.assertResponseLength2CodeOK(response);
- ITUtil.assertEqualsProperties(
- mapper.readValue(response[1], Property[].class));
+ ITUtilProperties.assertListProperties("?inactive=false", 1,
+ default_properties[0]);
- response = ITUtil.doGetJson(HTTP_IP_PORT_OLOG_PROPERTIES + "?inactive=true");
- ITUtil.assertResponseLength2CodeOK(response);
- ITUtil.assertEqualsProperties(
- mapper.readValue(response[1], Property[].class),
+ ITUtilProperties.assertListProperties("?inactive=true", 3,
property_p1_owner_a_state_i_attributes,
- property_p2_owner_a_state_i_attributes);
+ property_p2_owner_a_state_i_attributes,
+ default_properties[0]);
- response = ITUtil.doGetJson(HTTP_IP_PORT_OLOG_PROPERTIES);
- ITUtil.assertResponseLength2CodeOKContent(response, ITUtil.EMPTY_JSON);
+ ITUtilProperties.assertListProperties(1, default_properties[0]);
} catch (IOException e) {
fail();
- } catch (InterruptedException e) {
- fail();
} catch (Exception e) {
fail();
}
@@ -660,7 +559,7 @@ public void handleProperty2() {
* Test {@link org.phoebus.olog.OlogResourceDescriptors#PROPERTY_RESOURCE_URI}.
*/
@Test
- public void handleProperty3ChangeState() {
+ void handleProperty3ChangeState() {
// what
// replace property, change state
// --------------------------------------------------------------------------------
@@ -672,53 +571,40 @@ public void handleProperty3ChangeState() {
// Create Properties
// x Remove Property
- ObjectMapper mapper = new ObjectMapper();
-
try {
- String[] response = ITUtil.doGetJson(HTTP_IP_PORT_OLOG_PROPERTIES);
- ITUtil.assertResponseLength2CodeOKContent(response, ITUtil.EMPTY_JSON);
+ ITUtilProperties.assertListProperties(1, default_properties[0]);
- response = ITUtil.runShellCommand(createCurlPropertyForAdmin("p1", mapper.writeValueAsString(property_p1_owner_a_state_a_attributes)));
- ITUtil.assertResponseLength2CodeOK(response);
- assertEquals(property_p1_owner_a_state_a_attributes, mapper.readValue(response[1], Property.class));
+ ITUtilProperties.assertCreateProperty("/p1", property_p1_owner_a_state_a_attributes);
// refresh elastic indices
- response = ITUtil.refreshElasticIndices();
- ITUtil.assertResponseLength2CodeOK(response);
+ ITUtil.assertRefreshElasticIndices();
+
+ ITUtilProperties.assertListProperties(2,
+ property_p1_owner_a_state_a_attributes,
+ default_properties[0]);
- response = ITUtil.doGetJson(HTTP_IP_PORT_OLOG_PROPERTIES);
- ITUtil.assertResponseLength2CodeOK(response);
- ITUtil.assertEqualsProperties(
- mapper.readValue(response[1], Property[].class),
- property_p1_owner_a_state_a_attributes);
+ ITUtilProperties.assertRetrieveProperty("/p1", property_p1_owner_a_state_a_attributes);
- response = ITUtil.doGetJson(HTTP_IP_PORT_OLOG_PROPERTIES + "/p1");
- ITUtil.assertResponseLength2CodeOK(response);
- assertEquals(property_p1_owner_a_state_a_attributes, mapper.readValue(response[1], Property.class));
+ ITUtilProperties.assertCreateProperty("/p1", property_p1_owner_a_state_i_attributes);
- response = ITUtil.runShellCommand(createCurlPropertyForAdmin("p1", mapper.writeValueAsString(property_p1_owner_a_state_i_attributes)));
- ITUtil.assertResponseLength2CodeOK(response);
+ // refresh elastic indices
+ ITUtil.assertRefreshElasticIndices();
- response = ITUtil.doGetJson(HTTP_IP_PORT_OLOG_PROPERTIES);
- ITUtil.assertResponseLength2CodeOKContent(response, ITUtil.EMPTY_JSON);
+ ITUtilProperties.assertListProperties(1,
+ default_properties[0]);
- response = ITUtil.doGetJson(HTTP_IP_PORT_OLOG_PROPERTIES + "/p1");
- ITUtil.assertResponseLength2CodeOK(response);
- assertEquals(property_p1_owner_a_state_i_attributes, mapper.readValue(response[1], Property.class));
+ ITUtilProperties.assertRetrieveProperty("/p1", property_p1_owner_a_state_i_attributes);
- response = ITUtil.runShellCommand(deleteCurlPropertyForAdmin("p1"));
- ITUtil.assertResponseLength2CodeOK(response);
+ ITUtilProperties.assertRemoveProperty("/p1");
- response = ITUtil.doGetJson(HTTP_IP_PORT_OLOG_PROPERTIES + "/p1");
- ITUtil.assertResponseLength2CodeOK(response);
- assertEquals(property_p1_owner_a_state_i_attributes, mapper.readValue(response[1], Property.class));
+ // refresh elastic indices
+ ITUtil.assertRefreshElasticIndices();
- response = ITUtil.doGetJson(HTTP_IP_PORT_OLOG_PROPERTIES);
- ITUtil.assertResponseLength2CodeOKContent(response, ITUtil.EMPTY_JSON);
+ ITUtilProperties.assertRetrieveProperty("/p1", property_p1_owner_a_state_i_attributes);
+
+ ITUtilProperties.assertListProperties(1, default_properties[0]);
} catch (IOException e) {
fail();
- } catch (InterruptedException e) {
- fail();
} catch (Exception e) {
fail();
}
@@ -728,7 +614,7 @@ public void handleProperty3ChangeState() {
* Test {@link org.phoebus.olog.OlogResourceDescriptors#PROPERTY_RESOURCE_URI}.
*/
@Test
- public void handlePropertiesCreateCheck() {
+ void handlePropertiesCreateCheck() {
// what
// check(s) for create properties
// e.g.
@@ -749,94 +635,74 @@ public void handlePropertiesCreateCheck() {
// Remove Property
Property property_check = new Property();
+ Property[] properties = new Property[] {
+ property_p1_owner_a_state_a_attributes,
+ property_p2_owner_a_state_a_attributes,
+ property_p3_owner_a_state_a_attributes,
+ property_p4_owner_a_state_a_attributes,
+ property_p5_owner_a_state_a_attributes,
+ property_p6_owner_a_state_i_attributes,
+ property_p7_owner_a_state_i_attributes,
+ property_p8_owner_a_state_i_attributes,
+ property_p9_owner_a_state_i_attributes,
+ property_p10_owner_a_state_i_attributes,
+ property_check
+ };
Attribute attribute_check = new Attribute();
- ObjectMapper mapper = new ObjectMapper();
+ ITUtilProperties.assertListProperties(1, default_properties[0]);
- try {
- String[] response = ITUtil.doGetJson(HTTP_IP_PORT_OLOG_PROPERTIES);
- ITUtil.assertResponseLength2CodeOKContent(response, ITUtil.EMPTY_JSON);
+ ITUtilProperties.assertCreateProperties("", properties, HttpURLConnection.HTTP_BAD_REQUEST);
- Property[] properties = new Property[] {
- property_p1_owner_a_state_a_attributes,
- property_p2_owner_a_state_a_attributes,
- property_p3_owner_a_state_a_attributes,
- property_p4_owner_a_state_a_attributes,
- property_p5_owner_a_state_a_attributes,
- property_p6_owner_a_state_i_attributes,
- property_p7_owner_a_state_i_attributes,
- property_p8_owner_a_state_i_attributes,
- property_p9_owner_a_state_i_attributes,
- property_p10_owner_a_state_i_attributes,
- property_check
- };
-
- response = ITUtil.runShellCommand(createCurlPropertiesForAdmin(mapper.writeValueAsString(properties)));
- ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_BAD_REQUEST);
-
- property_check.setName(null);
- properties[10] = property_check;
-
- response = ITUtil.runShellCommand(createCurlPropertiesForAdmin(mapper.writeValueAsString(properties)));
- ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_BAD_REQUEST);
-
- property_check.setName("");
- properties[10] = property_check;
-
- response = ITUtil.runShellCommand(createCurlPropertiesForAdmin(mapper.writeValueAsString(properties)));
- ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_BAD_REQUEST);
-
- property_check.setName("asdf");
- property_check.setOwner("zxcv");
- property_check.setState(State.Active);
- property_check.setAttributes(null);
- properties[10] = property_check;
-
- response = ITUtil.runShellCommand(createCurlPropertiesForAdmin(mapper.writeValueAsString(properties)));
- ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_INTERNAL_ERROR);
-
- property_check = new Property();
- property_check.setName("asdf");
- property_check.setOwner("zxcv");
- property_check.setState(State.Active);
- property_check.addAttributes(attribute_check);
- properties[10] = property_check;
-
- response = ITUtil.runShellCommand(createCurlPropertiesForAdmin(mapper.writeValueAsString(properties)));
- ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_BAD_REQUEST);
-
- attribute_check.setName(null);
- property_check.getAttributes().clear();
- property_check.addAttributes(attribute_check);
- properties[10] = property_check;
-
- response = ITUtil.runShellCommand(createCurlPropertiesForAdmin(mapper.writeValueAsString(properties)));
- ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_BAD_REQUEST);
-
- attribute_check.setName("");
- property_check.getAttributes().clear();
- property_check.addAttributes(attribute_check);
- properties[10] = property_check;
-
- response = ITUtil.runShellCommand(createCurlPropertiesForAdmin(mapper.writeValueAsString(properties)));
- ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_BAD_REQUEST);
-
- response = ITUtil.doGetJson(HTTP_IP_PORT_OLOG_PROPERTIES);
- ITUtil.assertResponseLength2CodeOKContent(response, ITUtil.EMPTY_JSON);
- } catch (IOException e) {
- fail();
- } catch (InterruptedException e) {
- fail();
- } catch (Exception e) {
- fail();
- }
+ property_check.setName(null);
+ properties[10] = property_check;
+
+ ITUtilProperties.assertCreateProperties("", properties, HttpURLConnection.HTTP_BAD_REQUEST);
+
+ property_check.setName("");
+ properties[10] = property_check;
+
+ ITUtilProperties.assertCreateProperties("", properties, HttpURLConnection.HTTP_BAD_REQUEST);
+
+ property_check.setName("asdf");
+ property_check.setOwner("zxcv");
+ property_check.setState(State.Active);
+ property_check.setAttributes(null);
+ properties[10] = property_check;
+
+ ITUtilProperties.assertCreateProperties("", properties, HttpURLConnection.HTTP_INTERNAL_ERROR);
+
+ property_check = new Property();
+ property_check.setName("asdf");
+ property_check.setOwner("zxcv");
+ property_check.setState(State.Active);
+ property_check.addAttributes(attribute_check);
+ properties[10] = property_check;
+
+ ITUtilProperties.assertCreateProperties("", properties, HttpURLConnection.HTTP_BAD_REQUEST);
+
+ attribute_check.setName(null);
+ property_check.getAttributes().clear();
+ property_check.addAttributes(attribute_check);
+ properties[10] = property_check;
+
+ ITUtilProperties.assertCreateProperties("", properties, HttpURLConnection.HTTP_BAD_REQUEST);
+
+ attribute_check.setName("");
+ property_check.getAttributes().clear();
+ property_check.addAttributes(attribute_check);
+ properties[10] = property_check;
+
+ ITUtilProperties.assertCreateProperties("", properties, HttpURLConnection.HTTP_BAD_REQUEST);
+
+ ITUtilProperties.assertListProperties(1, default_properties[0]);
}
/**
* Test {@link org.phoebus.olog.OlogResourceDescriptors#PROPERTY_RESOURCE_URI}.
*/
@Test
- public void handleProperties() {
+ void handleProperties() {
// what
// create properties
// --------------------------------------------------------------------------------
@@ -874,210 +740,87 @@ public void handleProperties() {
property_p9_owner_a_state_i_attributes
};
- ObjectMapper mapper = new ObjectMapper();
-
try {
- String[] response = ITUtil.doGetJson(HTTP_IP_PORT_OLOG_PROPERTIES);
- ITUtil.assertResponseLength2CodeOKContent(response, ITUtil.EMPTY_JSON);
+ ITUtilProperties.assertListProperties(1, default_properties[0]);
- response = ITUtil.runShellCommand(createCurlPropertiesForAdmin(mapper.writeValueAsString(properties_active_inactive)));
- ITUtil.assertResponseLength2CodeOK(response);
- ITUtil.assertEqualsProperties(
- mapper.readValue(response[1], Property[].class),
- properties_active_inactive);
+ ITUtilProperties.assertCreateProperties("", properties_active_inactive);
// refresh elastic indices
- response = ITUtil.refreshElasticIndices();
- ITUtil.assertResponseLength2CodeOK(response);
+ ITUtil.assertRefreshElasticIndices();
- response = ITUtil.doGetJson(HTTP_IP_PORT_OLOG_PROPERTIES);
- ITUtil.assertResponseLength2CodeOK(response);
- ITUtil.assertEqualsProperties(
- mapper.readValue(response[1], Property[].class),
+ ITUtilProperties.assertListProperties(6,
property_p1_owner_a_state_a_attributes,
property_p2_owner_a_state_a_attributes,
property_p3_owner_a_state_a_attributes,
property_p4_owner_a_state_a_attributes,
- property_p5_owner_a_state_a_attributes);
+ property_p5_owner_a_state_a_attributes,
+ default_properties[0]);
- response = ITUtil.doGetJson(HTTP_IP_PORT_OLOG_PROPERTIES + "?inactive=false");
- ITUtil.assertResponseLength2CodeOK(response);
- ITUtil.assertEqualsProperties(
- mapper.readValue(response[1], Property[].class),
+ ITUtilProperties.assertListProperties("?inactive=false", 6,
property_p1_owner_a_state_a_attributes,
property_p2_owner_a_state_a_attributes,
property_p3_owner_a_state_a_attributes,
property_p4_owner_a_state_a_attributes,
- property_p5_owner_a_state_a_attributes);
+ property_p5_owner_a_state_a_attributes,
+ default_properties[0]);
- response = ITUtil.doGetJson(HTTP_IP_PORT_OLOG_PROPERTIES + "?inactive=true");
- ITUtil.assertResponseLength2CodeOK(response);
- ITUtil.assertEqualsProperties(
- mapper.readValue(response[1], Property[].class),
+ ITUtilProperties.assertListProperties("?inactive=true", 10,
properties_active_inactive);
- response = ITUtil.doGetJson(HTTP_IP_PORT_OLOG_PROPERTIES + "/p1");
- ITUtil.assertResponseLength2CodeOK(response);
- assertEquals(property_p1_owner_a_state_a_attributes, mapper.readValue(response[1], Property.class));
-
- response = ITUtil.doGetJson(HTTP_IP_PORT_OLOG_PROPERTIES + "/p2");
- ITUtil.assertResponseLength2CodeOK(response);
- assertEquals(property_p2_owner_a_state_a_attributes, mapper.readValue(response[1], Property.class));
-
- response = ITUtil.doGetJson(HTTP_IP_PORT_OLOG_PROPERTIES + "/p3");
- ITUtil.assertResponseLength2CodeOK(response);
- assertEquals(property_p3_owner_a_state_a_attributes, mapper.readValue(response[1], Property.class));
-
- response = ITUtil.doGetJson(HTTP_IP_PORT_OLOG_PROPERTIES + "/p4");
- ITUtil.assertResponseLength2CodeOK(response);
- assertEquals(property_p4_owner_a_state_a_attributes, mapper.readValue(response[1], Property.class));
-
- response = ITUtil.doGetJson(HTTP_IP_PORT_OLOG_PROPERTIES + "/p5");
- ITUtil.assertResponseLength2CodeOK(response);
- assertEquals(property_p5_owner_a_state_a_attributes, mapper.readValue(response[1], Property.class));
-
- response = ITUtil.doGetJson(HTTP_IP_PORT_OLOG_PROPERTIES + "/p6");
- ITUtil.assertResponseLength2CodeOK(response);
- assertEquals(property_p6_owner_a_state_i_attributes, mapper.readValue(response[1], Property.class));
-
- response = ITUtil.doGetJson(HTTP_IP_PORT_OLOG_PROPERTIES + "/p7");
- ITUtil.assertResponseLength2CodeOK(response);
- assertEquals(property_p7_owner_a_state_i_attributes, mapper.readValue(response[1], Property.class));
-
- response = ITUtil.doGetJson(HTTP_IP_PORT_OLOG_PROPERTIES + "/p8");
- ITUtil.assertResponseLength2CodeOK(response);
- assertEquals(property_p8_owner_a_state_i_attributes, mapper.readValue(response[1], Property.class));
-
- response = ITUtil.doGetJson(HTTP_IP_PORT_OLOG_PROPERTIES + "/p9");
- ITUtil.assertResponseLength2CodeOK(response);
- assertEquals(property_p9_owner_a_state_i_attributes, mapper.readValue(response[1], Property.class));
-
- response = ITUtil.doGetJson(HTTP_IP_PORT_OLOG_PROPERTIES + "/p10");
- ITUtil.assertResponseLength2CodeOK(response);
- assertEquals(property_p10_owner_a_state_i_attributes, mapper.readValue(response[1], Property.class));
+ ITUtilProperties.assertRetrieveProperty("/p1", property_p1_owner_a_state_a_attributes);
+ ITUtilProperties.assertRetrieveProperty("/p2", property_p2_owner_a_state_a_attributes);
+ ITUtilProperties.assertRetrieveProperty("/p3", property_p3_owner_a_state_a_attributes);
+ ITUtilProperties.assertRetrieveProperty("/p4", property_p4_owner_a_state_a_attributes);
+ ITUtilProperties.assertRetrieveProperty("/p5", property_p5_owner_a_state_a_attributes);
+ ITUtilProperties.assertRetrieveProperty("/p6", property_p6_owner_a_state_i_attributes);
+ ITUtilProperties.assertRetrieveProperty("/p7", property_p7_owner_a_state_i_attributes);
+ ITUtilProperties.assertRetrieveProperty("/p8", property_p8_owner_a_state_i_attributes);
+ ITUtilProperties.assertRetrieveProperty("/p9", property_p9_owner_a_state_i_attributes);
+ ITUtilProperties.assertRetrieveProperty("/p10", property_p10_owner_a_state_i_attributes);
+
+ ITUtilProperties.assertRemoveProperty("/p1");
+ ITUtilProperties.assertRemoveProperty("/p2");
+ ITUtilProperties.assertRemoveProperty("/p3");
+ ITUtilProperties.assertRemoveProperty("/p9");
+ ITUtilProperties.assertRemoveProperty("/p10");
- response = ITUtil.runShellCommand(deleteCurlPropertyForAdmin("p1"));
- ITUtil.assertResponseLength2CodeOK(response);
-
- response = ITUtil.runShellCommand(deleteCurlPropertyForAdmin("p2"));
- ITUtil.assertResponseLength2CodeOK(response);
-
- response = ITUtil.runShellCommand(deleteCurlPropertyForAdmin("p3"));
- ITUtil.assertResponseLength2CodeOK(response);
-
- response = ITUtil.runShellCommand(deleteCurlPropertyForAdmin("p9"));
- ITUtil.assertResponseLength2CodeOK(response);
-
- response = ITUtil.runShellCommand(deleteCurlPropertyForAdmin("p10"));
- ITUtil.assertResponseLength2CodeOK(response);
+ // refresh elastic indices
+ ITUtil.assertRefreshElasticIndices();
- response = ITUtil.doGetJson(HTTP_IP_PORT_OLOG_PROPERTIES);
- ITUtil.assertResponseLength2CodeOK(response);
- ITUtil.assertEqualsProperties(
- mapper.readValue(response[1], Property[].class),
+ ITUtilProperties.assertListProperties(3,
property_p4_owner_a_state_a_attributes,
- property_p5_owner_a_state_a_attributes);
+ property_p5_owner_a_state_a_attributes,
+ default_properties[0]);
- response = ITUtil.doGetJson(HTTP_IP_PORT_OLOG_PROPERTIES + "?inactive=false");
- ITUtil.assertResponseLength2CodeOK(response);
- ITUtil.assertEqualsProperties(
- mapper.readValue(response[1], Property[].class),
+ ITUtilProperties.assertListProperties("?inactive=false", 3,
property_p4_owner_a_state_a_attributes,
- property_p5_owner_a_state_a_attributes);
+ property_p5_owner_a_state_a_attributes,
+ default_properties[0]);
- response = ITUtil.doGetJson(HTTP_IP_PORT_OLOG_PROPERTIES + "?inactive=true");
- ITUtil.assertResponseLength2CodeOK(response);
- ITUtil.assertEqualsProperties(
- mapper.readValue(response[1], Property[].class),
+ ITUtilProperties.assertListProperties("?inactive=true", 10,
properties_active_inactive);
- response = ITUtil.runShellCommand(deleteCurlPropertyForAdmin("p4"));
- ITUtil.assertResponseLength2CodeOK(response);
-
- response = ITUtil.runShellCommand(deleteCurlPropertyForAdmin("p5"));
- ITUtil.assertResponseLength2CodeOK(response);
-
- response = ITUtil.runShellCommand(deleteCurlPropertyForAdmin("p6"));
- ITUtil.assertResponseLength2CodeOK(response);
+ ITUtilProperties.assertRemoveProperty("/p4");
+ ITUtilProperties.assertRemoveProperty("/p5");
+ ITUtilProperties.assertRemoveProperty("/p6");
+ ITUtilProperties.assertRemoveProperty("/p7");
+ ITUtilProperties.assertRemoveProperty("/p8");
- response = ITUtil.runShellCommand(deleteCurlPropertyForAdmin("p7"));
- ITUtil.assertResponseLength2CodeOK(response);
-
- response = ITUtil.runShellCommand(deleteCurlPropertyForAdmin("p8"));
- ITUtil.assertResponseLength2CodeOK(response);
+ // refresh elastic indices
+ ITUtil.assertRefreshElasticIndices();
- response = ITUtil.doGetJson(HTTP_IP_PORT_OLOG_PROPERTIES + "?inactive=false");
- ITUtil.assertResponseLength2CodeOK(response);
- ITUtil.assertEqualsProperties(
- mapper.readValue(response[1], Property[].class));
+ ITUtilProperties.assertListProperties("?inactive=false", 1,
+ default_properties[0]);
- response = ITUtil.doGetJson(HTTP_IP_PORT_OLOG_PROPERTIES + "?inactive=true");
- ITUtil.assertResponseLength2CodeOK(response);
- ITUtil.assertEqualsProperties(
- mapper.readValue(response[1], Property[].class),
+ ITUtilProperties.assertListProperties("?inactive=true", 10,
properties_inactive);
- response = ITUtil.doGetJson(HTTP_IP_PORT_OLOG_PROPERTIES);
- ITUtil.assertResponseLength2CodeOKContent(response, ITUtil.EMPTY_JSON);
+ ITUtilProperties.assertListProperties(1, default_properties[0]);
} catch (IOException e) {
fail();
- } catch (InterruptedException e) {
- fail();
} catch (Exception e) {
fail();
}
}
- /**
- * Utility method to return curl to create property for regular user.
- *
- * @param propertyName property name
- * @param propertyJson property json
- * @return curl to create property
- */
- private static String createCurlPropertyForUser(String propertyName, String propertyJson) {
- return "curl -H " + ITUtil.HEADER_JSON + " -XPUT -i " + HTTP_AUTH_USER_IP_PORT_OLOG_PROPERTIES + "/" + propertyName + " -d '" + propertyJson + "'";
- }
-
- /**
- * Utility method to return curl to create property for admin user.
- *
- * @param propertyName property name
- * @param propertyJson property json
- * @return curl to create property
- */
- private static String createCurlPropertyForAdmin(String propertyName, String propertyJson) {
- return "curl -H " + ITUtil.HEADER_JSON + " -XPUT -i " + HTTP_AUTH_ADMIN_IP_PORT_OLOG_PROPERTIES + "/" + propertyName + " -d '" + propertyJson + "'";
- }
-
- /**
- * Utility method to return curl to create properties for admin user.
- *
- * @param propertiesJson properties json
- * @return curl to create properties
- */
- private static String createCurlPropertiesForAdmin(String propertiesJson) {
- return "curl -H " + ITUtil.HEADER_JSON + " -XPUT -i " + HTTP_AUTH_ADMIN_IP_PORT_OLOG_PROPERTIES + " -d '" + propertiesJson + "'";
- }
-
- /**
- * Utility method to return curl to delete property for regular user.
- *
- * @param propertyName property name
- * @return curl to delete property
- */
- private static String deleteCurlPropertyForUser(String propertyName) {
- return "curl -H " + ITUtil.HEADER_JSON + " -XDELETE -i " + HTTP_AUTH_USER_IP_PORT_OLOG_PROPERTIES + "/" + propertyName;
- }
-
- /**
- * Utility method to return curl to delete property for admin user.
- *
- * @param propertyName property name
- * @return curl to delete property
- */
- private static String deleteCurlPropertyForAdmin(String propertyName) {
- return "curl -H " + ITUtil.HEADER_JSON + " -XDELETE -i " + HTTP_AUTH_ADMIN_IP_PORT_OLOG_PROPERTIES + "/" + propertyName;
- }
-
}
diff --git a/src/test/java/org/phoebus/olog/docker/OlogTagsIT.java b/src/test/java/org/phoebus/olog/docker/OlogTagsIT.java
index c8056d8..aabafc6 100644
--- a/src/test/java/org/phoebus/olog/docker/OlogTagsIT.java
+++ b/src/test/java/org/phoebus/olog/docker/OlogTagsIT.java
@@ -1,21 +1,33 @@
/*
* Copyright (C) 2021 European Spallation Source ERIC.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
package org.phoebus.olog.docker;
-import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
+import org.phoebus.olog.docker.ITUtil.AuthorizationChoice;
import org.phoebus.olog.entity.State;
import org.phoebus.olog.entity.Tag;
-import org.testcontainers.containers.DockerComposeContainer;
-import org.testcontainers.containers.wait.strategy.Wait;
+import org.testcontainers.containers.ComposeContainer;
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;
-import java.io.File;
import java.io.IOException;
import java.net.HttpURLConnection;
@@ -35,7 +47,7 @@
* @see org.phoebus.olog.TagsResource
*/
@Testcontainers
-public class OlogTagsIT {
+class OlogTagsIT {
// Note
// ------------------------------------------------------------------------------------------------
@@ -56,25 +68,21 @@ public class OlogTagsIT {
// Olog - Service Documentation
// https://olog.readthedocs.io/en/latest/
// ------------------------------------------------------------------------------------------------
- // OLOG API TagResource
- // -------------------- --------------------
- // Retrieve a Tag .../tags/ (GET) findByTitle(String)
- // List Tags .../tags (GET) findAll()
- // Create a Tag .../tags/ (PUT) createTag(String, Tag)
- // Create Tags .../tags (PUT) updateTag(List)
- // Remove Tag .../tags/ (DELETE) deleteTag(String)
+ // OLOG API TagResource
+ // -------------------- --------------------
+ // Retrieve a Tag .../tags/ (GET) findByTitle(String)
+ // List Tags .../tags (GET) findAll()
+ // Create a Tag .../tags/ (PUT) createTag(String, Tag)
+ // Create Tags .../tags (PUT) updateTag(List)
+ // Remove Tag .../tags/ (DELETE) deleteTag(String)
// ------------------------------------------------------------------------------------------------
- static final String TAGS = "/tags";
-
- static final String HTTP_IP_PORT_OLOG_TAGS = ITUtil.HTTP + ITUtil.IP_PORT_OLOG + TAGS;
- static final String HTTP_AUTH_USER_IP_PORT_OLOG_TAGS = ITUtil.HTTP + ITUtil.AUTH_USER + "@" + ITUtil.IP_PORT_OLOG + TAGS;
- static final String HTTP_AUTH_ADMIN_IP_PORT_OLOG_TAGS = ITUtil.HTTP + ITUtil.AUTH_ADMIN + "@" + ITUtil.IP_PORT_OLOG + TAGS;
-
// test data
// tags t1 - t10, state Active - Inactive
// tags t1 - t2, state Inactive
+ static Tag[] default_tags;
+
static Tag tag_t1_state_a;
static Tag tag_t2_state_a;
static Tag tag_t3_state_a;
@@ -90,12 +98,12 @@ public class OlogTagsIT {
static Tag tag_t2_state_i;
@Container
- public static final DockerComposeContainer> ENVIRONMENT =
- new DockerComposeContainer<>(new File("docker-compose.yml"))
- .waitingFor(ITUtil.OLOG, Wait.forLogMessage(".*Started Application.*", 1));
+ public static final ComposeContainer ENVIRONMENT = ITUtil.defaultComposeContainers();
@BeforeAll
public static void setupObjects() {
+ default_tags = new Tag[] {new Tag("alarm", State.Active)};
+
tag_t1_state_a = new Tag("t1", State.Active);
tag_t2_state_a = new Tag("t2", State.Active);
tag_t3_state_a = new Tag("t3", State.Active);
@@ -113,6 +121,8 @@ public static void setupObjects() {
@AfterAll
public static void tearDownObjects() {
+ default_tags = null;
+
tag_t1_state_a = null;
tag_t2_state_a = null;
tag_t3_state_a = null;
@@ -128,8 +138,15 @@ public static void tearDownObjects() {
tag_t2_state_i = null;
}
+ @AfterAll
+ public static void extractJacocoReport() {
+ // extract jacoco report from container file system
+ ITUtil.extractJacocoReport(ENVIRONMENT,
+ ITUtil.JACOCO_TARGET_PREFIX + OlogTagsIT.class.getSimpleName() + ITUtil.JACOCO_TARGET_SUFFIX);
+ }
+
@Test
- public void ologUp() {
+ void ologUp() {
try {
String address = ITUtil.HTTP_IP_PORT_OLOG;
int responseCode = ITUtil.doGet(address);
@@ -144,7 +161,7 @@ public void ologUp() {
* Test {@link org.phoebus.olog.OlogResourceDescriptors#TAG_RESOURCE_URI}.
*/
@Test
- public void handleTagRetrieveCheck() {
+ void handleTagRetrieveCheck() {
// what
// check(s) for retrieve tag
// e.g.
@@ -156,19 +173,14 @@ public void handleTagRetrieveCheck() {
// Create Tags
// Remove Tag
- try {
- String[] response = ITUtil.doGetJson(HTTP_IP_PORT_OLOG_TAGS + "/t11");
- ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_NOT_FOUND);
- } catch (IOException e) {
- fail();
- }
+ ITUtilTags.assertRetrieveTag("/t11", HttpURLConnection.HTTP_NOT_FOUND);
}
/**
* Test {@link org.phoebus.olog.OlogResourceDescriptors#TAG_RESOURCE_URI}.
*/
@Test
- public void handleTagRemoveCheck() {
+ void handleTagRemoveCheck() {
// what
// check(s) for remove tag
// e.g.
@@ -180,27 +192,21 @@ public void handleTagRemoveCheck() {
// Create Tags
// x Remove Tag
- try {
- // might be both 401, 404
- // 401 UNAUTHORIZED
- // 404 NOT_FOUND
- String[] response = ITUtil.runShellCommand(deleteCurlTagForUser("t11"));
- ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_NOT_FOUND);
-
- response = ITUtil.runShellCommand(deleteCurlTagForAdmin("t11"));
- ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_NOT_FOUND);
- } catch (IOException e) {
- fail();
- } catch (Exception e) {
- fail();
- }
+ // might be both 401, 404
+ // 401 UNAUTHORIZED
+ // 404 NOT_FOUND
+
+ // check permissions
+
+ ITUtilTags.assertRemoveTag(AuthorizationChoice.USER, "/t11", HttpURLConnection.HTTP_NOT_FOUND);
+ ITUtilTags.assertRemoveTag(AuthorizationChoice.ADMIN, "/t11", HttpURLConnection.HTTP_NOT_FOUND);
}
/**
* Test {@link org.phoebus.olog.OlogResourceDescriptors#TAG_RESOURCE_URI}.
*/
@Test
- public void handleTagCreateCheckJson() {
+ void handleTagCreateCheckJson() {
// what
// check(s) for create tag
// e.g.
@@ -229,59 +235,28 @@ public void handleTagCreateCheckJson() {
String json_tag_t1_state_empty = "{\"name\":\"t1\",\"state\":\"\"}";
String json_tag_t1_state_asdf = "{\"name\":\"t1\",\"state\":\"asdf\"}";
- try {
- String[] response = ITUtil.doGetJson(HTTP_IP_PORT_OLOG_TAGS);
- ITUtil.assertResponseLength2CodeOKContent(response, ITUtil.EMPTY_JSON);
-
- response = ITUtil.runShellCommand(createCurlTagForAdmin("t1", json_incomplete1));
- ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_BAD_REQUEST);
-
- response = ITUtil.runShellCommand(createCurlTagForAdmin("t1", json_incomplete2));
- ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_BAD_REQUEST);
-
- response = ITUtil.runShellCommand(createCurlTagForAdmin("t1", json_incomplete3));
- ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_BAD_REQUEST);
-
- response = ITUtil.runShellCommand(createCurlTagForAdmin("t1", json_incomplete4));
- ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_BAD_REQUEST);
-
- response = ITUtil.runShellCommand(createCurlTagForAdmin("t1", json_incomplete5));
- ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_BAD_REQUEST);
-
- response = ITUtil.runShellCommand(createCurlTagForAdmin("t1", json_incomplete7));
- ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_BAD_REQUEST);
-
- response = ITUtil.runShellCommand(createCurlTagForAdmin("t1", json_incomplete8));
- ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_BAD_REQUEST);
-
- response = ITUtil.runShellCommand(createCurlTagForAdmin("t1", json_incomplete9));
- ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_BAD_REQUEST);
-
- response = ITUtil.runShellCommand(createCurlTagForAdmin("t1", json_tag_t1_name_na));
- ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_BAD_REQUEST);
-
- response = ITUtil.runShellCommand(createCurlTagForAdmin("t1", json_tag_t1_state_empty));
- ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_BAD_REQUEST);
-
- response = ITUtil.runShellCommand(createCurlTagForAdmin("t1", json_tag_t1_state_asdf));
- ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_BAD_REQUEST);
-
- response = ITUtil.doGetJson(HTTP_IP_PORT_OLOG_TAGS);
- ITUtil.assertResponseLength2CodeOKContent(response, ITUtil.EMPTY_JSON);
- } catch (IOException e) {
- fail();
- } catch (InterruptedException e) {
- fail();
- } catch (Exception e) {
- fail();
- }
+ ITUtilTags.assertListTags(1, default_tags[0]);
+
+ ITUtilTags.assertCreateTag(AuthorizationChoice.ADMIN, "/t1", json_incomplete1, HttpURLConnection.HTTP_BAD_REQUEST);
+ ITUtilTags.assertCreateTag(AuthorizationChoice.ADMIN, "/t1", json_incomplete2, HttpURLConnection.HTTP_BAD_REQUEST);
+ ITUtilTags.assertCreateTag(AuthorizationChoice.ADMIN, "/t1", json_incomplete3, HttpURLConnection.HTTP_BAD_REQUEST);
+ ITUtilTags.assertCreateTag(AuthorizationChoice.ADMIN, "/t1", json_incomplete4, HttpURLConnection.HTTP_BAD_REQUEST);
+ ITUtilTags.assertCreateTag(AuthorizationChoice.ADMIN, "/t1", json_incomplete5, HttpURLConnection.HTTP_BAD_REQUEST);
+ ITUtilTags.assertCreateTag(AuthorizationChoice.ADMIN, "/t1", json_incomplete7, HttpURLConnection.HTTP_BAD_REQUEST);
+ ITUtilTags.assertCreateTag(AuthorizationChoice.ADMIN, "/t1", json_incomplete8, HttpURLConnection.HTTP_BAD_REQUEST);
+ ITUtilTags.assertCreateTag(AuthorizationChoice.ADMIN, "/t1", json_incomplete9, HttpURLConnection.HTTP_BAD_REQUEST);
+ ITUtilTags.assertCreateTag(AuthorizationChoice.ADMIN, "/t1", json_tag_t1_name_na, HttpURLConnection.HTTP_BAD_REQUEST);
+ ITUtilTags.assertCreateTag(AuthorizationChoice.ADMIN, "/t1", json_tag_t1_state_empty, HttpURLConnection.HTTP_BAD_REQUEST);
+ ITUtilTags.assertCreateTag(AuthorizationChoice.ADMIN, "/t1", json_tag_t1_state_asdf, HttpURLConnection.HTTP_BAD_REQUEST);
+
+ ITUtilTags.assertListTags(1, default_tags[0]);
}
/**
* Test {@link org.phoebus.olog.OlogResourceDescriptors#TAG_RESOURCE_URI}.
*/
@Test
- public void handleTagCreateCheck() {
+ void handleTagCreateCheck() {
// what
// check(s) for create tag
// e.g.
@@ -299,47 +274,30 @@ public void handleTagCreateCheck() {
Tag tag_check = new Tag();
- ObjectMapper mapper = new ObjectMapper();
-
- try {
- String[] response = ITUtil.doGetJson(HTTP_IP_PORT_OLOG_TAGS);
- ITUtil.assertResponseLength2CodeOKContent(response, ITUtil.EMPTY_JSON);
-
- // response = ITUtil.runShellCommand(createCurlTagForUser("t1", mapper.writeValueAsString(tag_t1_state_a)));
- // ITUtil.assertResponseLength2Code(HttpURLConnection.HTTP_UNAUTHORIZED, response);
+ ITUtilTags.assertListTags(1, default_tags[0]);
- response = ITUtil.runShellCommand(createCurlTagForUser("asdf", mapper.writeValueAsString(tag_check)));
- ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_BAD_REQUEST);
+ // check permissions
+ // ITUtilTags.assertCreateTag(AuthorizationChoice.USER, "/t1", tag_t1_state_a, HttpURLConnection.HTTP_UNAUTHORIZED);
- response = ITUtil.runShellCommand(createCurlTagForAdmin("asdf", mapper.writeValueAsString(tag_check)));
- ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_BAD_REQUEST);
+ ITUtilTags.assertCreateTag(AuthorizationChoice.USER, "/asdf", tag_check, HttpURLConnection.HTTP_BAD_REQUEST);
+ ITUtilTags.assertCreateTag(AuthorizationChoice.ADMIN, "/asdf", tag_check, HttpURLConnection.HTTP_BAD_REQUEST);
- tag_check.setName(null);
+ tag_check.setName(null);
- response = ITUtil.runShellCommand(createCurlTagForAdmin("asdf", mapper.writeValueAsString(tag_check)));
- ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_BAD_REQUEST);
+ ITUtilTags.assertCreateTag(AuthorizationChoice.ADMIN, "/asdf", tag_check, HttpURLConnection.HTTP_BAD_REQUEST);
- tag_check.setName("");
+ tag_check.setName("");
- response = ITUtil.runShellCommand(createCurlTagForAdmin("asdf", mapper.writeValueAsString(tag_check)));
- ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_BAD_REQUEST);
+ ITUtilTags.assertCreateTag(AuthorizationChoice.ADMIN, "/asdf", tag_check, HttpURLConnection.HTTP_BAD_REQUEST);
- response = ITUtil.doGetJson(HTTP_IP_PORT_OLOG_TAGS);
- ITUtil.assertResponseLength2CodeOKContent(response, ITUtil.EMPTY_JSON);
- } catch (IOException e) {
- fail();
- } catch (InterruptedException e) {
- fail();
- } catch (Exception e) {
- fail();
- }
+ ITUtilTags.assertListTags(1, default_tags[0]);
}
/**
* Test {@link org.phoebus.olog.OlogResourceDescriptors#TAG_RESOURCE_URI}.
*/
@Test
- public void handleTag() {
+ void handleTag() {
// what
// user with required role TagMod
// create tag
@@ -352,46 +310,33 @@ public void handleTag() {
// Create Tags
// x Remove Tag
- ObjectMapper mapper = new ObjectMapper();
-
try {
- String[] response = ITUtil.doGetJson(HTTP_IP_PORT_OLOG_TAGS);
- ITUtil.assertResponseLength2CodeOKContent(response, ITUtil.EMPTY_JSON);
+ ITUtilTags.assertListTags(1, default_tags[0]);
- response = ITUtil.runShellCommand(createCurlTagForAdmin("t1", mapper.writeValueAsString(tag_t1_state_a)));
- ITUtil.assertResponseLength2CodeOK(response);
- assertEquals(tag_t1_state_a, mapper.readValue(response[1], Tag.class));
+ ITUtilTags.assertCreateTag("/t1", tag_t1_state_a);
// refresh elastic indices
- response = ITUtil.refreshElasticIndices();
- ITUtil.assertResponseLength2CodeOK(response);
+ ITUtil.assertRefreshElasticIndices();
- response = ITUtil.doGetJson(HTTP_IP_PORT_OLOG_TAGS);
- ITUtil.assertResponseLength2CodeOK(response);
- ITUtil.assertEqualsTags(
- mapper.readValue(response[1], Tag[].class),
+ ITUtilTags.assertListTags(2,
+ default_tags[0],
tag_t1_state_a);
- response = ITUtil.doGetJson(HTTP_IP_PORT_OLOG_TAGS + "/t1");
- ITUtil.assertResponseLength2CodeOK(response);
- assertEquals(tag_t1_state_a, mapper.readValue(response[1], Tag.class));
+ ITUtilTags.assertRetrieveTag("/t1", tag_t1_state_a);
+
+ // check permissions
+ // ITUtilTags.assertRemoveTag(AuthorizationChoice.USER, "/t1", HttpURLConnection.HTTP_UNAUTHORIZED);
- // response = ITUtil.runShellCommand(deleteCurlTagForUser("t1"));
- // ITUtil.assertResponseLength2Code(HttpURLConnection.HTTP_UNAUTHORIZED, response);
+ ITUtilTags.assertRemoveTag("/t1");
- response = ITUtil.runShellCommand(deleteCurlTagForAdmin("t1"));
- ITUtil.assertResponseLength2CodeOK(response);
+ // refresh elastic indices
+ ITUtil.assertRefreshElasticIndices();
- response = ITUtil.doGetJson(HTTP_IP_PORT_OLOG_TAGS + "/t1");
- ITUtil.assertResponseLength2CodeOK(response);
- assertEquals(tag_t1_state_i, mapper.readValue(response[1], Tag.class));
+ ITUtilTags.assertRetrieveTag("/t1", tag_t1_state_i);
- response = ITUtil.doGetJson(HTTP_IP_PORT_OLOG_TAGS);
- ITUtil.assertResponseLength2CodeOKContent(response, ITUtil.EMPTY_JSON);
+ ITUtilTags.assertListTags(1, default_tags[0]);
} catch (IOException e) {
fail();
- } catch (InterruptedException e) {
- fail();
} catch (Exception e) {
fail();
}
@@ -401,7 +346,7 @@ public void handleTag() {
* Test {@link org.phoebus.olog.OlogResourceDescriptors#TAG_RESOURCE_URI}.
*/
@Test
- public void handleTag2() {
+ void handleTag2() {
// what
// create tags, one by one
// --------------------------------------------------------------------------------
@@ -413,65 +358,44 @@ public void handleTag2() {
// Create Tags
// x Remove Tag
- ObjectMapper mapper = new ObjectMapper();
-
try {
- String[] response = ITUtil.doGetJson(HTTP_IP_PORT_OLOG_TAGS);
- ITUtil.assertResponseLength2CodeOKContent(response, ITUtil.EMPTY_JSON);
-
- response = ITUtil.runShellCommand(createCurlTagForAdmin("t1", mapper.writeValueAsString(tag_t1_state_a)));
- ITUtil.assertResponseLength2CodeOK(response);
- assertEquals(tag_t1_state_a, mapper.readValue(response[1], Tag.class));
+ ITUtilTags.assertListTags(1, default_tags[0]);
- response = ITUtil.runShellCommand(createCurlTagForAdmin("t2", mapper.writeValueAsString(tag_t2_state_a)));
- ITUtil.assertResponseLength2CodeOK(response);
- assertEquals(tag_t2_state_a, mapper.readValue(response[1], Tag.class));
+ ITUtilTags.assertCreateTag("/t1", tag_t1_state_a);
+ ITUtilTags.assertCreateTag("/t2", tag_t2_state_a);
// refresh elastic indices
- response = ITUtil.refreshElasticIndices();
- ITUtil.assertResponseLength2CodeOK(response);
+ ITUtil.assertRefreshElasticIndices();
- response = ITUtil.doGetJson(HTTP_IP_PORT_OLOG_TAGS);
- ITUtil.assertResponseLength2CodeOK(response);
- ITUtil.assertEqualsTags(
- mapper.readValue(response[1], Tag[].class),
+ ITUtilTags.assertListTags(3,
+ default_tags[0],
tag_t1_state_a,
tag_t2_state_a);
- response = ITUtil.doGetJson(HTTP_IP_PORT_OLOG_TAGS + "/t1");
- ITUtil.assertResponseLength2CodeOK(response);
- assertEquals(tag_t1_state_a, mapper.readValue(response[1], Tag.class));
+ ITUtilTags.assertRetrieveTag("/t1", tag_t1_state_a);
+ ITUtilTags.assertRetrieveTag("/t2", tag_t2_state_a);
- response = ITUtil.doGetJson(HTTP_IP_PORT_OLOG_TAGS + "/t2");
- ITUtil.assertResponseLength2CodeOK(response);
- assertEquals(tag_t2_state_a, mapper.readValue(response[1], Tag.class));
+ ITUtilTags.assertRemoveTag("/t1");
- response = ITUtil.runShellCommand(deleteCurlTagForAdmin("t1"));
- ITUtil.assertResponseLength2CodeOK(response);
+ // refresh elastic indices
+ ITUtil.assertRefreshElasticIndices();
- response = ITUtil.doGetJson(HTTP_IP_PORT_OLOG_TAGS);
- ITUtil.assertResponseLength2CodeOK(response);
- ITUtil.assertEqualsTags(
- mapper.readValue(response[1], Tag[].class),
+ ITUtilTags.assertListTags(2,
+ default_tags[0],
tag_t2_state_a);
- response = ITUtil.doGetJson(HTTP_IP_PORT_OLOG_TAGS + "/t1");
- ITUtil.assertResponseLength2CodeOK(response);
- assertEquals(tag_t1_state_i, mapper.readValue(response[1], Tag.class));
+ ITUtilTags.assertRetrieveTag("/t1", tag_t1_state_i);
+
+ ITUtilTags.assertRemoveTag("/t2");
- response = ITUtil.runShellCommand(deleteCurlTagForAdmin("t2"));
- ITUtil.assertResponseLength2CodeOK(response);
+ // refresh elastic indices
+ ITUtil.assertRefreshElasticIndices();
- response = ITUtil.doGetJson(HTTP_IP_PORT_OLOG_TAGS + "/t2");
- ITUtil.assertResponseLength2CodeOK(response);
- assertEquals(tag_t2_state_i, mapper.readValue(response[1], Tag.class));
+ ITUtilTags.assertRetrieveTag("/t2", tag_t2_state_i);
- response = ITUtil.doGetJson(HTTP_IP_PORT_OLOG_TAGS);
- ITUtil.assertResponseLength2CodeOKContent(response, ITUtil.EMPTY_JSON);
+ ITUtilTags.assertListTags(1, default_tags[0]);
} catch (IOException e) {
fail();
- } catch (InterruptedException e) {
- fail();
} catch (Exception e) {
fail();
}
@@ -481,7 +405,7 @@ public void handleTag2() {
* Test {@link org.phoebus.olog.OlogResourceDescriptors#TAG_RESOURCE_URI}.
*/
@Test
- public void handleTag3ChangeState() {
+ void handleTag3ChangeState() {
// what
// replace tag, change state
// --------------------------------------------------------------------------------
@@ -493,53 +417,39 @@ public void handleTag3ChangeState() {
// Create Tags
// x Remove Tag
- ObjectMapper mapper = new ObjectMapper();
-
try {
- String[] response = ITUtil.doGetJson(HTTP_IP_PORT_OLOG_TAGS);
- ITUtil.assertResponseLength2CodeOKContent(response, ITUtil.EMPTY_JSON);
+ ITUtilTags.assertListTags(1, default_tags[0]);
- response = ITUtil.runShellCommand(createCurlTagForAdmin("t1", mapper.writeValueAsString(tag_t1_state_a)));
- ITUtil.assertResponseLength2CodeOK(response);
- assertEquals(tag_t1_state_a, mapper.readValue(response[1], Tag.class));
+ ITUtilTags.assertCreateTag("/t1", tag_t1_state_a);
// refresh elastic indices
- response = ITUtil.refreshElasticIndices();
- ITUtil.assertResponseLength2CodeOK(response);
+ ITUtil.assertRefreshElasticIndices();
- response = ITUtil.doGetJson(HTTP_IP_PORT_OLOG_TAGS);
- ITUtil.assertResponseLength2CodeOK(response);
- ITUtil.assertEqualsTags(
- mapper.readValue(response[1], Tag[].class),
+ ITUtilTags.assertListTags(2,
+ default_tags[0],
tag_t1_state_a);
- response = ITUtil.doGetJson(HTTP_IP_PORT_OLOG_TAGS + "/t1");
- ITUtil.assertResponseLength2CodeOK(response);
- assertEquals(tag_t1_state_a, mapper.readValue(response[1], Tag.class));
+ ITUtilTags.assertRetrieveTag("/t1", tag_t1_state_a);
+
+ ITUtilTags.assertCreateTag("/t1", tag_t1_state_i);
+
+ // refresh elastic indices
+ ITUtil.assertRefreshElasticIndices();
- response = ITUtil.runShellCommand(createCurlTagForAdmin("t1", mapper.writeValueAsString(tag_t1_state_i)));
- ITUtil.assertResponseLength2CodeOK(response);
+ ITUtilTags.assertListTags(1, default_tags[0]);
- response = ITUtil.doGetJson(HTTP_IP_PORT_OLOG_TAGS);
- ITUtil.assertResponseLength2CodeOKContent(response, ITUtil.EMPTY_JSON);
+ ITUtilTags.assertRetrieveTag("/t1", tag_t1_state_i);
- response = ITUtil.doGetJson(HTTP_IP_PORT_OLOG_TAGS + "/t1");
- ITUtil.assertResponseLength2CodeOK(response);
- assertEquals(tag_t1_state_i, mapper.readValue(response[1], Tag.class));
+ ITUtilTags.assertRemoveTag("/t1");
- response = ITUtil.runShellCommand(deleteCurlTagForAdmin("t1"));
- ITUtil.assertResponseLength2CodeOK(response);
+ // refresh elastic indices
+ ITUtil.assertRefreshElasticIndices();
- response = ITUtil.doGetJson(HTTP_IP_PORT_OLOG_TAGS + "/t1");
- ITUtil.assertResponseLength2CodeOK(response);
- assertEquals(tag_t1_state_i, mapper.readValue(response[1], Tag.class));
+ ITUtilTags.assertRetrieveTag("/t1", tag_t1_state_i);
- response = ITUtil.doGetJson(HTTP_IP_PORT_OLOG_TAGS);
- ITUtil.assertResponseLength2CodeOKContent(response, ITUtil.EMPTY_JSON);
+ ITUtilTags.assertListTags(1, default_tags[0]);
} catch (IOException e) {
fail();
- } catch (InterruptedException e) {
- fail();
} catch (Exception e) {
fail();
}
@@ -549,7 +459,7 @@ public void handleTag3ChangeState() {
* Test {@link org.phoebus.olog.OlogResourceDescriptors#TAG_RESOURCE_URI}.
*/
@Test
- public void handleTagsCreateCheck() {
+ void handleTagsCreateCheck() {
// what
// check(s) for create tags
// e.g.
@@ -566,58 +476,42 @@ public void handleTagsCreateCheck() {
// Remove Tag
Tag tag_check = new Tag();
+ Tag[] tags = new Tag[] {
+ tag_t1_state_a,
+ tag_t2_state_a,
+ tag_t3_state_a,
+ tag_t4_state_a,
+ tag_t5_state_a,
+ tag_t6_state_i,
+ tag_t7_state_i,
+ tag_t8_state_i,
+ tag_t9_state_i,
+ tag_t10_state_i,
+ tag_check
+ };
- ObjectMapper mapper = new ObjectMapper();
+ ITUtilTags.assertListTags(1, default_tags[0]);
- try {
- String[] response = ITUtil.doGetJson(HTTP_IP_PORT_OLOG_TAGS);
- ITUtil.assertResponseLength2CodeOKContent(response, ITUtil.EMPTY_JSON);
+ ITUtilTags.assertCreateTags("", tags, HttpURLConnection.HTTP_BAD_REQUEST);
- Tag[] tags = new Tag[] {
- tag_t1_state_a,
- tag_t2_state_a,
- tag_t3_state_a,
- tag_t4_state_a,
- tag_t5_state_a,
- tag_t6_state_i,
- tag_t7_state_i,
- tag_t8_state_i,
- tag_t9_state_i,
- tag_t10_state_i,
- tag_check
- };
+ tag_check.setName(null);
+ tags[10] = tag_check;
- response = ITUtil.runShellCommand(createCurlTagsForAdmin(mapper.writeValueAsString(tags)));
- ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_BAD_REQUEST);
+ ITUtilTags.assertCreateTags("", tags, HttpURLConnection.HTTP_BAD_REQUEST);
- tag_check.setName(null);
- tags[10] = tag_check;
+ tag_check.setName("");
+ tags[10] = tag_check;
- response = ITUtil.runShellCommand(createCurlTagsForAdmin(mapper.writeValueAsString(tags)));
- ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_BAD_REQUEST);
+ ITUtilTags.assertCreateTags("", tags, HttpURLConnection.HTTP_BAD_REQUEST);
- tag_check.setName("");
- tags[10] = tag_check;
-
- response = ITUtil.runShellCommand(createCurlTagsForAdmin(mapper.writeValueAsString(tags)));
- ITUtil.assertResponseLength2Code(response, HttpURLConnection.HTTP_BAD_REQUEST);
-
- response = ITUtil.doGetJson(HTTP_IP_PORT_OLOG_TAGS);
- ITUtil.assertResponseLength2CodeOKContent(response, ITUtil.EMPTY_JSON);
- } catch (IOException e) {
- fail();
- } catch (InterruptedException e) {
- fail();
- } catch (Exception e) {
- fail();
- }
+ ITUtilTags.assertListTags(1, default_tags[0]);
}
/**
* Test {@link org.phoebus.olog.OlogResourceDescriptors#TAG_RESOURCE_URI}.
*/
@Test
- public void handleTags() {
+ void handleTags() {
// what
// create tags
// --------------------------------------------------------------------------------
@@ -642,170 +536,62 @@ public void handleTags() {
tag_t10_state_i
};
- ObjectMapper mapper = new ObjectMapper();
-
try {
- String[] response = ITUtil.doGetJson(HTTP_IP_PORT_OLOG_TAGS);
- ITUtil.assertResponseLength2CodeOKContent(response, ITUtil.EMPTY_JSON);
+ ITUtilTags.assertListTags(1, default_tags[0]);
- response = ITUtil.runShellCommand(createCurlTagsForAdmin(mapper.writeValueAsString(tags_active_inactive)));
- ITUtil.assertResponseLength2CodeOK(response);
- ITUtil.assertEqualsTags(
- mapper.readValue(response[1], Tag[].class),
- tags_active_inactive);
+ ITUtilTags.assertCreateTags("", tags_active_inactive);
// refresh elastic indices
- response = ITUtil.refreshElasticIndices();
- ITUtil.assertResponseLength2CodeOK(response);
+ ITUtil.assertRefreshElasticIndices();
- response = ITUtil.doGetJson(HTTP_IP_PORT_OLOG_TAGS);
- ITUtil.assertResponseLength2CodeOK(response);
- ITUtil.assertEqualsTags(
- mapper.readValue(response[1], Tag[].class),
+ ITUtilTags.assertListTags(6,
+ default_tags[0],
tag_t1_state_a,
tag_t2_state_a,
tag_t3_state_a,
tag_t4_state_a,
tag_t5_state_a);
- response = ITUtil.doGetJson(HTTP_IP_PORT_OLOG_TAGS + "/t1");
- ITUtil.assertResponseLength2CodeOK(response);
- assertEquals(tag_t1_state_a, mapper.readValue(response[1], Tag.class));
-
- response = ITUtil.doGetJson(HTTP_IP_PORT_OLOG_TAGS + "/t2");
- ITUtil.assertResponseLength2CodeOK(response);
- assertEquals(tag_t2_state_a, mapper.readValue(response[1], Tag.class));
-
- response = ITUtil.doGetJson(HTTP_IP_PORT_OLOG_TAGS + "/t3");
- ITUtil.assertResponseLength2CodeOK(response);
- assertEquals(tag_t3_state_a, mapper.readValue(response[1], Tag.class));
-
- response = ITUtil.doGetJson(HTTP_IP_PORT_OLOG_TAGS + "/t4");
- ITUtil.assertResponseLength2CodeOK(response);
- assertEquals(tag_t4_state_a, mapper.readValue(response[1], Tag.class));
-
- response = ITUtil.doGetJson(HTTP_IP_PORT_OLOG_TAGS + "/t5");
- ITUtil.assertResponseLength2CodeOK(response);
- assertEquals(tag_t5_state_a, mapper.readValue(response[1], Tag.class));
-
- response = ITUtil.doGetJson(HTTP_IP_PORT_OLOG_TAGS + "/t6");
- ITUtil.assertResponseLength2CodeOK(response);
- assertEquals(tag_t6_state_i, mapper.readValue(response[1], Tag.class));
-
- response = ITUtil.doGetJson(HTTP_IP_PORT_OLOG_TAGS + "/t7");
- ITUtil.assertResponseLength2CodeOK(response);
- assertEquals(tag_t7_state_i, mapper.readValue(response[1], Tag.class));
-
- response = ITUtil.doGetJson(HTTP_IP_PORT_OLOG_TAGS + "/t8");
- ITUtil.assertResponseLength2CodeOK(response);
- assertEquals(tag_t8_state_i, mapper.readValue(response[1], Tag.class));
+ ITUtilTags.assertRetrieveTag("/t1", tag_t1_state_a);
+ ITUtilTags.assertRetrieveTag("/t2", tag_t2_state_a);
+ ITUtilTags.assertRetrieveTag("/t3", tag_t3_state_a);
+ ITUtilTags.assertRetrieveTag("/t4", tag_t4_state_a);
+ ITUtilTags.assertRetrieveTag("/t5", tag_t5_state_a);
+ ITUtilTags.assertRetrieveTag("/t6", tag_t6_state_i);
+ ITUtilTags.assertRetrieveTag("/t7", tag_t7_state_i);
+ ITUtilTags.assertRetrieveTag("/t8", tag_t8_state_i);
+ ITUtilTags.assertRetrieveTag("/t9", tag_t9_state_i);
+ ITUtilTags.assertRetrieveTag("/t10", tag_t10_state_i);
+
+ ITUtilTags.assertRemoveTag("/t1");
+ ITUtilTags.assertRemoveTag("/t2");
+ ITUtilTags.assertRemoveTag("/t3");
+ ITUtilTags.assertRemoveTag("/t9");
+ ITUtilTags.assertRemoveTag("/t10");
- response = ITUtil.doGetJson(HTTP_IP_PORT_OLOG_TAGS + "/t9");
- ITUtil.assertResponseLength2CodeOK(response);
- assertEquals(tag_t9_state_i, mapper.readValue(response[1], Tag.class));
-
- response = ITUtil.doGetJson(HTTP_IP_PORT_OLOG_TAGS + "/t10");
- ITUtil.assertResponseLength2CodeOK(response);
- assertEquals(tag_t10_state_i, mapper.readValue(response[1], Tag.class));
-
- response = ITUtil.runShellCommand(deleteCurlTagForAdmin("t1"));
- ITUtil.assertResponseLength2CodeOK(response);
-
- response = ITUtil.runShellCommand(deleteCurlTagForAdmin("t2"));
- ITUtil.assertResponseLength2CodeOK(response);
-
- response = ITUtil.runShellCommand(deleteCurlTagForAdmin("t3"));
- ITUtil.assertResponseLength2CodeOK(response);
-
- response = ITUtil.runShellCommand(deleteCurlTagForAdmin("t9"));
- ITUtil.assertResponseLength2CodeOK(response);
-
- response = ITUtil.runShellCommand(deleteCurlTagForAdmin("t10"));
- ITUtil.assertResponseLength2CodeOK(response);
+ // refresh elastic indices
+ ITUtil.assertRefreshElasticIndices();
- response = ITUtil.doGetJson(HTTP_IP_PORT_OLOG_TAGS);
- ITUtil.assertResponseLength2CodeOK(response);
- ITUtil.assertEqualsTags(
- mapper.readValue(response[1], Tag[].class),
+ ITUtilTags.assertListTags(3,
+ default_tags[0],
tag_t4_state_a,
tag_t5_state_a);
- response = ITUtil.runShellCommand(deleteCurlTagForAdmin("t4"));
- ITUtil.assertResponseLength2CodeOK(response);
-
- response = ITUtil.runShellCommand(deleteCurlTagForAdmin("t5"));
- ITUtil.assertResponseLength2CodeOK(response);
+ ITUtilTags.assertRemoveTag("/t4");
+ ITUtilTags.assertRemoveTag("/t5");
+ ITUtilTags.assertRemoveTag("/t6");
+ ITUtilTags.assertRemoveTag("/t7");
+ ITUtilTags.assertRemoveTag("/t8");
- response = ITUtil.runShellCommand(deleteCurlTagForAdmin("t6"));
- ITUtil.assertResponseLength2CodeOK(response);
-
- response = ITUtil.runShellCommand(deleteCurlTagForAdmin("t7"));
- ITUtil.assertResponseLength2CodeOK(response);
-
- response = ITUtil.runShellCommand(deleteCurlTagForAdmin("t8"));
- ITUtil.assertResponseLength2CodeOK(response);
+ // refresh elastic indices
+ ITUtil.assertRefreshElasticIndices();
- response = ITUtil.doGetJson(HTTP_IP_PORT_OLOG_TAGS);
- ITUtil.assertResponseLength2CodeOK(response);
+ ITUtilTags.assertListTags(1, default_tags[0]);
} catch (IOException e) {
fail();
- } catch (InterruptedException e) {
- fail();
} catch (Exception e) {
fail();
}
}
- /**
- * Utility method to return curl to create tag for regular user.
- *
- * @param tagName tag name
- * @param tagJson tag json
- * @return curl to create tag
- */
- private static String createCurlTagForUser(String tagName, String tagJson) {
- return "curl -H " + ITUtil.HEADER_JSON + " -XPUT -i " + HTTP_AUTH_USER_IP_PORT_OLOG_TAGS + "/" + tagName + " -d '" + tagJson + "'";
- }
-
- /**
- * Utility method to return curl to create tag for admin user.
- *
- * @param tagName tag name
- * @param tagJson tag json
- * @return curl to create tag
- */
- private static String createCurlTagForAdmin(String tagName, String tagJson) {
- return "curl -H " + ITUtil.HEADER_JSON + " -XPUT -i " + HTTP_AUTH_ADMIN_IP_PORT_OLOG_TAGS + "/" + tagName + " -d '" + tagJson + "'";
- }
-
- /**
- * Utility method to return curl to create tags for admin user.
- *
- * @param tagsJson tags json
- * @return curl to create tags
- */
- private static String createCurlTagsForAdmin(String tagsJson) {
- return "curl -H " + ITUtil.HEADER_JSON + " -XPUT -i " + HTTP_AUTH_ADMIN_IP_PORT_OLOG_TAGS + " -d '" + tagsJson + "'";
- }
-
- /**
- * Utility method to return curl to delete tag for regular user.
- *
- * @param tagName tag name
- * @return curl to delete tag
- */
- private static String deleteCurlTagForUser(String tagName) {
- return "curl -H " + ITUtil.HEADER_JSON + " -XDELETE -i " + HTTP_AUTH_USER_IP_PORT_OLOG_TAGS + "/" + tagName;
- }
-
- /**
- * Utility method to return curl to delete tag for admin user.
- *
- * @param tagName tag name
- * @return curl to delete tag
- */
- private static String deleteCurlTagForAdmin(String tagName) {
- return "curl -H " + ITUtil.HEADER_JSON + " -XDELETE -i " + HTTP_AUTH_ADMIN_IP_PORT_OLOG_TAGS + "/" + tagName;
- }
-
}
diff --git a/src/test/java/org/phoebus/olog/entity/InstanceDeserialzerTest.java b/src/test/java/org/phoebus/olog/entity/InstanceDeserialzerTest.java
index 029755e..ea4708d 100644
--- a/src/test/java/org/phoebus/olog/entity/InstanceDeserialzerTest.java
+++ b/src/test/java/org/phoebus/olog/entity/InstanceDeserialzerTest.java
@@ -27,10 +27,10 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.when;
-public class InstanceDeserialzerTest {
+class InstanceDeserialzerTest {
@Test
- public void testDeserialize() throws Exception{
+ void testDeserialize() throws Exception {
JsonParser jsonParser = Mockito.mock(JsonParser.class);
when(jsonParser.getText()).thenReturn("1622550277.005000000");
InstanceDeserializer instanceDeserializer = new InstanceDeserializer();
diff --git a/src/test/java/org/phoebus/olog/entity/LogEntryGroupHelperTest.java b/src/test/java/org/phoebus/olog/entity/LogEntryGroupHelperTest.java
index e8dcc4e..a59f4a2 100644
--- a/src/test/java/org/phoebus/olog/entity/LogEntryGroupHelperTest.java
+++ b/src/test/java/org/phoebus/olog/entity/LogEntryGroupHelperTest.java
@@ -52,8 +52,7 @@ public static void init() {
}
@Test
- public void testAddLogEntryGroupPorpertyNoProperties(){
-
+ void testAddLogEntryGroupPorpertyNoProperties() {
Log originalLog = LogBuilder.createLog()
.owner("user")
.title("original title")
@@ -69,8 +68,7 @@ public void testAddLogEntryGroupPorpertyNoProperties(){
}
@Test
- public void testAddLogEntryGroupPorpertyOriginalHasLogEntryGroup(){
-
+ void testAddLogEntryGroupPorpertyOriginalHasLogEntryGroup() {
Log originalLog = LogBuilder.createLog()
.owner("user")
.title("original title")
diff --git a/src/test/java/org/phoebus/olog/entity/PropertyTest.java b/src/test/java/org/phoebus/olog/entity/PropertyTest.java
index 59f4a79..1c58a8f 100644
--- a/src/test/java/org/phoebus/olog/entity/PropertyTest.java
+++ b/src/test/java/org/phoebus/olog/entity/PropertyTest.java
@@ -25,10 +25,10 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
-public class PropertyTest {
+class PropertyTest {
@Test
- public void testEquals(){
+ void testEquals() {
Property p1 = new Property();
Property p2 = new Property();
assertEquals(p1, p2);
@@ -52,7 +52,7 @@ public void testEquals(){
}
@Test
- public void testHashCode(){
+ void testHashCode() {
Property p1 = new Property();
Property p2 = new Property();
assertEquals(p1.hashCode(), p2.hashCode());
diff --git a/src/test/java/org/phoebus/olog/entity/ServiceConfigurationTest.java b/src/test/java/org/phoebus/olog/entity/ServiceConfigurationTest.java
index 9aa4c01..339ea95 100644
--- a/src/test/java/org/phoebus/olog/entity/ServiceConfigurationTest.java
+++ b/src/test/java/org/phoebus/olog/entity/ServiceConfigurationTest.java
@@ -22,10 +22,10 @@
import static org.junit.jupiter.api.Assertions.assertNull;
-public class ServiceConfigurationTest {
+class ServiceConfigurationTest {
@Test
- public void testNoArgsConstructor() {
+ void testNoArgsConstructor() {
ServiceConfiguration serviceConfiguration = new ServiceConfiguration();
assertNull(serviceConfiguration.getLevels());
assertNull(serviceConfiguration.getTags());
diff --git a/src/test/java/org/phoebus/olog/entity/preprocess/CommonmarkPreprocessorTest.java b/src/test/java/org/phoebus/olog/entity/preprocess/CommonmarkPreprocessorTest.java
index adb6571..3520826 100644
--- a/src/test/java/org/phoebus/olog/entity/preprocess/CommonmarkPreprocessorTest.java
+++ b/src/test/java/org/phoebus/olog/entity/preprocess/CommonmarkPreprocessorTest.java
@@ -26,12 +26,12 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
-public class CommonmarkPreprocessorTest {
+class CommonmarkPreprocessorTest {
private final CommonmarkCleaner commonmarkPreprocessor = new CommonmarkCleaner();
@Test
- public void testDescriptionNonNull(){
+ void testDescriptionNonNull() {
Log log = LogBuilder.createLog()
.source("**BOLD** ![alt](http://foo.bar)")
.description(null)
@@ -44,7 +44,7 @@ public void testDescriptionNonNull(){
}
@Test
- public void testDescriptionNull(){
+ void testDescriptionNull() {
Log log = LogBuilder.createLog()
.description(null)
.source(null)
diff --git a/src/test/java/org/phoebus/olog/entity/preprocess/DefaultPreprocessorTest.java b/src/test/java/org/phoebus/olog/entity/preprocess/DefaultPreprocessorTest.java
index 930b7f3..822dedc 100644
--- a/src/test/java/org/phoebus/olog/entity/preprocess/DefaultPreprocessorTest.java
+++ b/src/test/java/org/phoebus/olog/entity/preprocess/DefaultPreprocessorTest.java
@@ -25,12 +25,12 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
-public class DefaultPreprocessorTest {
+class DefaultPreprocessorTest {
private DefaultMarkupCleaner defaultPreprocessor = new DefaultMarkupCleaner();
@Test
- public void testSourceNull(){
+ void testSourceNull() {
Log log = LogBuilder.createLog()
.description("description")
.source(null)
diff --git a/src/test/java/org/phoebus/olog/security/SessionFilterTest.java b/src/test/java/org/phoebus/olog/security/SessionFilterTest.java
index 9952b5c..967da82 100644
--- a/src/test/java/org/phoebus/olog/security/SessionFilterTest.java
+++ b/src/test/java/org/phoebus/olog/security/SessionFilterTest.java
@@ -72,7 +72,7 @@ public static void init() {
}
@Test
- public void testGetAuthorizationFromCookie() {
+ void testGetAuthorizationFromCookie() {
HttpServletRequest httpServletRequest = Mockito.mock(HttpServletRequest.class);
when(httpServletRequest.getCookies()).thenReturn(null);
@@ -103,7 +103,7 @@ public void testGetAuthorizationFromCookie() {
}
@Test
- public void testGetUsernameAndPasswordFromAuthorizationHeader() {
+ void testGetUsernameAndPasswordFromAuthorizationHeader() {
assertNull(sessionFilter.getUsernameAndPassword(null));
assertNull(sessionFilter.getUsernameAndPassword("Does not start with Basic"));
@@ -113,7 +113,7 @@ public void testGetUsernameAndPasswordFromAuthorizationHeader() {
}
@Test
- public void testFilterWithoutCookieOrAuthenticationHeader() throws Exception {
+ void testFilterWithoutCookieOrAuthenticationHeader() throws Exception {
HttpServletRequest httpServletRequest = Mockito.mock(HttpServletRequest.class);
when(httpServletRequest.getCookies()).thenReturn(null);
when(httpServletRequest.getHeader("Authorization")).thenReturn(null);
@@ -127,7 +127,7 @@ public void testFilterWithoutCookieOrAuthenticationHeader() throws Exception {
}
@Test
- public void testFilterWithNullSession() throws Exception {
+ void testFilterWithNullSession() throws Exception {
HttpServletRequest httpServletRequest = Mockito.mock(HttpServletRequest.class);
when(httpServletRequest.getCookies()).thenReturn(cookies);
when(sessionRepository.findById("abc")).thenReturn(null);
@@ -136,7 +136,7 @@ public void testFilterWithNullSession() throws Exception {
}
@Test
- public void testFilterWithValidSession() throws Exception {
+ void testFilterWithValidSession() throws Exception {
HttpServletRequest httpServletRequest = Mockito.mock(HttpServletRequest.class);
when(httpServletRequest.getCookies()).thenReturn(cookies);
Session session = mock(Session.class);
@@ -152,7 +152,7 @@ public void testFilterWithValidSession() throws Exception {
}
@Test
- public void testFilterWithWrongAuthorizationHeader() throws Exception {
+ void testFilterWithWrongAuthorizationHeader() throws Exception {
HttpServletRequest httpServletRequest = Mockito.mock(HttpServletRequest.class);
when(httpServletRequest.getCookies()).thenReturn(null);
when(httpServletRequest.getHeader("Authorization")).thenReturn("wrong header value");
@@ -161,7 +161,7 @@ public void testFilterWithWrongAuthorizationHeader() throws Exception {
}
@Test
- public void testFilterWithInvalidAuthorizationHeader() throws Exception {
+ void testFilterWithInvalidAuthorizationHeader() throws Exception {
HttpServletRequest httpServletRequest = Mockito.mock(HttpServletRequest.class);
when(httpServletRequest.getCookies()).thenReturn(null);
when(httpServletRequest.getHeader("Authorization")).thenReturn("Basic YWRtaW46YWRtaW5QYXNz");
@@ -171,7 +171,7 @@ public void testFilterWithInvalidAuthorizationHeader() throws Exception {
}
@Test
- public void testFilterWithValidAuthorizationHeader() throws Exception {
+ void testFilterWithValidAuthorizationHeader() throws Exception {
HttpServletRequest httpServletRequest = Mockito.mock(HttpServletRequest.class);
when(httpServletRequest.getCookies()).thenReturn(null);
when(httpServletRequest.getHeader("Authorization")).thenReturn("Basic YWRtaW46YWRtaW5QYXNz");
diff --git a/src/test/java/org/phoebus/util/time/TimeIntervalTest.java b/src/test/java/org/phoebus/util/time/TimeIntervalTest.java
index 4ed9013..b50bfbf 100644
--- a/src/test/java/org/phoebus/util/time/TimeIntervalTest.java
+++ b/src/test/java/org/phoebus/util/time/TimeIntervalTest.java
@@ -18,68 +18,68 @@
*
* @author carcassi
*/
-public class TimeIntervalTest {
+class TimeIntervalTest {
@Test
- public void interval1() {
+ void interval1() {
TimeInterval interval = TimeInterval.between(Instant.ofEpochSecond(0, 0), Instant.ofEpochSecond(3600, 0));
assertThat(interval.getStart(), equalTo(Instant.ofEpochSecond(0, 0)));
assertThat(interval.getEnd(), equalTo(Instant.ofEpochSecond(3600, 0)));
}
@Test
- public void interval2() {
+ void interval2() {
TimeInterval interval = TimeInterval.between(Instant.ofEpochSecond(3600, 0), Instant.ofEpochSecond(7200, 0));
assertThat(interval.getStart(), equalTo(Instant.ofEpochSecond(3600, 0)));
assertThat(interval.getEnd(), equalTo(Instant.ofEpochSecond(7200, 0)));
}
@Test
- public void interval3() {
+ void interval3() {
TimeInterval interval = TimeInterval.between(Instant.ofEpochSecond(0, 0), null);
assertThat(interval.getStart(), equalTo(Instant.ofEpochSecond(0, 0)));
assertThat(interval.getEnd(), nullValue());
}
@Test
- public void interval4() {
+ void interval4() {
TimeInterval interval = TimeInterval.between(null, Instant.ofEpochSecond(0, 0));
assertThat(interval.getStart(), nullValue());
assertThat(interval.getEnd(), equalTo(Instant.ofEpochSecond(0, 0)));
}
@Test
- public void equals1() {
+ void equals1() {
TimeInterval interval = TimeInterval.between(Instant.ofEpochSecond(0, 0), Instant.ofEpochSecond(3600, 0));
assertThat(interval, equalTo(TimeInterval.between(Instant.ofEpochSecond(0, 0), Instant.ofEpochSecond(3600, 0))));
}
@Test
- public void equals2() {
+ void equals2() {
TimeInterval interval = TimeInterval.between(Instant.ofEpochSecond(0, 1), Instant.ofEpochSecond(3600, 0));
assertThat(interval, not(equalTo(TimeInterval.between(Instant.ofEpochSecond(0, 0), Instant.ofEpochSecond(3600, 0)))));
}
@Test
- public void equals3() {
+ void equals3() {
TimeInterval interval = TimeInterval.between(Instant.ofEpochSecond(0, 0), Instant.ofEpochSecond(3600, 1));
assertThat(interval, not(equalTo(TimeInterval.between(Instant.ofEpochSecond(0, 0), Instant.ofEpochSecond(3600, 0)))));
}
@Test
- public void equals4() {
+ void equals4() {
TimeInterval interval = TimeInterval.between(Instant.ofEpochSecond(0, 0), null);
assertThat(interval, equalTo(TimeInterval.between(Instant.ofEpochSecond(0, 0), null)));
}
@Test
- public void equals5() {
+ void equals5() {
TimeInterval interval = TimeInterval.between(null, Instant.ofEpochSecond(0, 0));
assertThat(interval, equalTo(TimeInterval.between(null, Instant.ofEpochSecond(0, 0))));
}
@Test
- public void contains1() {
+ void contains1() {
TimeInterval interval = TimeInterval.between(Instant.ofEpochSecond(0, 0), Instant.ofEpochSecond(3600, 1));
assertThat(interval.contains(Instant.ofEpochSecond(3,0)), is(true));
assertThat(interval.contains(Instant.ofEpochSecond(0,110)), is(true));
@@ -89,7 +89,7 @@ public void contains1() {
}
@Test
- public void contains2() {
+ void contains2() {
TimeInterval interval = TimeInterval.between(Instant.ofEpochSecond(0, 0), null);
assertThat(interval.contains(Instant.ofEpochSecond(-3600,2)), is(false));
assertThat(interval.contains(Instant.ofEpochSecond(-1,110)), is(false));
@@ -99,7 +99,7 @@ public void contains2() {
}
@Test
- public void contains3() {
+ void contains3() {
TimeInterval interval = TimeInterval.between(null, Instant.ofEpochSecond(0, 0));
assertThat(interval.contains(Instant.ofEpochSecond(-3600,2)), is(true));
assertThat(interval.contains(Instant.ofEpochSecond(-1,110)), is(true));
diff --git a/src/test/java/org/phoebus/util/time/TimeParserTest.java b/src/test/java/org/phoebus/util/time/TimeParserTest.java
index e2b24fc..d40d767 100644
--- a/src/test/java/org/phoebus/util/time/TimeParserTest.java
+++ b/src/test/java/org/phoebus/util/time/TimeParserTest.java
@@ -20,10 +20,10 @@
* @author shroffk
*/
@SuppressWarnings("nls")
-public class TimeParserTest {
+class TimeParserTest {
@Test
- public void parse() {
+ void parse() {
Instant now = Instant.now();
// create time interval using string to define relative start and end
// times
@@ -39,7 +39,7 @@ public void parse() {
*
*/
@Test
- public void parseRelativeInterval() {
+ void parseRelativeInterval() {
// Create an interval for January
TimeRelativeInterval interval = TimeRelativeInterval.of(TimeParser.parseTemporalAmount("1 month"), LocalDateTime
.parse("2011-02-01T00:00:00", DateTimeFormatter.ISO_LOCAL_DATE_TIME).toInstant(ZoneOffset.UTC));
@@ -64,8 +64,7 @@ public void parseRelativeInterval() {
}
@Test
- public void testParseTemporalAmount()
- {
+ void testParseTemporalAmount() {
TemporalAmount amount = TimeParser.parseTemporalAmount("3 days");
long seconds = LocalDateTime.ofEpochSecond(0, 0, ZoneOffset.UTC).plus(amount).toEpochSecond(ZoneOffset.UTC);
assertEquals(3*24*60*60, seconds);
@@ -102,8 +101,7 @@ public void testParseTemporalAmount()
}
@Test
- public void testParseFactionalTemporalAmount()
- {
+ void testParseFactionalTemporalAmount() {
// Just having ".0" used to be an error before fractions were supported
TemporalAmount amount = TimeParser.parseTemporalAmount("1.000 hour");
System.out.println(TimeParser.format(amount));
@@ -166,8 +164,7 @@ public void testParseFactionalTemporalAmount()
}
@Test
- public void testFormatTemporalAmount()
- {
+ void testFormatTemporalAmount() {
String text = TimeParser.format(Duration.ofHours(2));
assertEquals("2 hours", text);
diff --git a/src/test/java/org/phoebus/util/time/TimeRelativeIntervalTest.java b/src/test/java/org/phoebus/util/time/TimeRelativeIntervalTest.java
index d384fd3..bcca46c 100644
--- a/src/test/java/org/phoebus/util/time/TimeRelativeIntervalTest.java
+++ b/src/test/java/org/phoebus/util/time/TimeRelativeIntervalTest.java
@@ -25,7 +25,7 @@
*
* @author carcassi, shroffk
*/
-public class TimeRelativeIntervalTest {
+class TimeRelativeIntervalTest {
public TimeRelativeIntervalTest() {
}
@@ -34,7 +34,7 @@ public TimeRelativeIntervalTest() {
* Absolute start and absolute end
*/
@Test
- public void interval1() {
+ void interval1() {
TimeRelativeInterval interval = TimeRelativeInterval.of(Instant.ofEpochSecond(0, 0),
Instant.ofEpochSecond(3600, 0));
assertThat(interval.toAbsoluteInterval(Instant.now()),
@@ -45,7 +45,7 @@ public void interval1() {
* absolute start and relative end
*/
@Test
- public void interval2() {
+ void interval2() {
// relative end of 10 ns after start
TimeRelativeInterval interval = TimeRelativeInterval.of(Instant.ofEpochSecond(0, 0), Duration.ofNanos(10));
assertThat(interval.toAbsoluteInterval(),
@@ -72,7 +72,7 @@ public void interval2() {
* relative start and absolute end
*/
@Test
- public void interval3() {
+ void interval3() {
// relative start of 10 ns before now
Instant now = Instant.now();
TimeRelativeInterval interval = TimeRelativeInterval.of(Duration.ofNanos(10), now);
@@ -92,7 +92,7 @@ public void interval3() {
}
@Test
- public void relativeIntervalinMilliSecs() {
+ void relativeIntervalinMilliSecs() {
TimeRelativeInterval interval = TimeRelativeInterval.of(ofMillis(15), ofMillis(5));
Instant now = Instant.now();
TimeInterval timeInterval = interval.toAbsoluteInterval(now);
@@ -101,7 +101,7 @@ public void relativeIntervalinMilliSecs() {
}
@Test
- public void relativeIntervalinSecs() {
+ void relativeIntervalinSecs() {
TimeRelativeInterval interval = TimeRelativeInterval.of(ofSeconds(5), ofSeconds(3));
Instant now = Instant.now();
TimeInterval timeInterval = interval.toAbsoluteInterval(now);
@@ -110,7 +110,7 @@ public void relativeIntervalinSecs() {
}
@Test
- public void relativeIntervalinMins() {
+ void relativeIntervalinMins() {
TimeRelativeInterval interval = TimeRelativeInterval.of(ofMinutes(5), ofMinutes(3));
Instant now = Instant.now();
TimeInterval timeInterval = interval.toAbsoluteInterval(now);
@@ -119,7 +119,7 @@ public void relativeIntervalinMins() {
}
@Test
- public void relativeIntervalinHours() {
+ void relativeIntervalinHours() {
TimeRelativeInterval interval = TimeRelativeInterval.of(ofHours(5), ofHours(3));
Instant now = Instant.now();
TimeInterval timeInterval = interval.toAbsoluteInterval(now);
@@ -131,10 +131,10 @@ public void relativeIntervalinHours() {
* The {@link TimeRelativeInterval} is defined with both the start and the
* end as relative definition. The below tests create an interval which
* represents a single month.
- *
+ *
*/
@Test
- public void relativeIntervalinDays1() {
+ void relativeIntervalinDays1() {
// Create an interval for January
TimeRelativeInterval interval = TimeRelativeInterval.of(ofMonths(1), ofMonths(0));
// Check jan it is 31 days
@@ -154,7 +154,7 @@ public void relativeIntervalinDays1() {
}
@Test
- public void relativeIntervalinDays2() {
+ void relativeIntervalinDays2() {
// Create an interval for January
TimeRelativeInterval interval = TimeRelativeInterval.of(LocalDateTime
.parse("2011-01-01T00:00:00", DateTimeFormatter.ISO_LOCAL_DATE_TIME).toInstant(ZoneOffset.UTC),
diff --git a/src/test/resources/INTEGRATIONTEST_DOCKER_RUN.md b/src/test/resources/INTEGRATIONTEST_DOCKER_RUN.md
new file mode 100644
index 0000000..a26db1a
--- /dev/null
+++ b/src/test/resources/INTEGRATIONTEST_DOCKER_RUN.md
@@ -0,0 +1,91 @@
+### Prerequisites
+
+##### Tools
+
+* Docker - engine 18.06.0+ or later, compose 2.21.0 or later, compose file version 3.7 to be supported
+
+##### Build ChannelFinder service
+
+```
+mvn clean install -Pdeployable-jar
+```
+
+### Run tests
+
+##### IDE
+
+All or individual integration tests (including methods) can be run in IDE as JUnit tests.
+
+##### Maven
+
+All integration tests can be run via Maven.
+
+```
+mvn failsafe:integration-test -DskipITs=false -Pintegrationtest-docker
+mvn failsafe:integration-test -DskipITs=false -DskipITCoverage=false -Pintegrationtest-docker
+```
+
+Individual integration tests (classes) can also be run via Maven.
+
+```
+mvn test -Dtest=org.phoebus.olog.docker.OlogIT
+mvn test -Dtest=org.phoebus.olog.docker.OlogLogbooksIT
+mvn test -Dtest=org.phoebus.olog.docker.OlogLogsIT
+mvn test -Dtest=org.phoebus.olog.docker.OlogLogsQueryIT
+mvn test -Dtest=org.phoebus.olog.docker.OlogPropertiesIT
+mvn test -Dtest=org.phoebus.olog.docker.OlogTagsIT
+```
+
+##### Code coverage
+
+Run integration tests with property `-DskipITCoverage=false` in order to have code coverage analysis. By default, code coverage for integration tests is disabled.
+
+After integration tests have been run, run below command to process coverage data. This applies for all and individual integration tests (including methods).
+
+```
+mvn verify -Djacoco.skip=false
+```
+
+Result is available in `target/site/jacoco` folder and includes code coverage execution data and reports.
+
+```
+index.html
+jacoco.exec
+jacoco.csv
+jacoco.xml
+```
+
+##### Summary
+
+To build and run all unit tests and integration tests (Docker)
+
+```
+mvn clean install test-compile failsafe:integration-test failsafe:verify --batch-mode --fail-at-end -DskipITs=false -Pdeployable-jar -Pintegrationtest-docker
+```
+
+To build and run all unit tests and integration tests (Docker) with code coverage.
+
+```
+mvn clean install test-compile failsafe:integration-test failsafe:verify verify --batch-mode --fail-at-end -Djacoco.skip=false -DskipITs=false -DskipITCoverage=false -Pdeployable-jar -Pintegrationtest-docker
+```
+
+### Note
+
+##### Build
+
+* (Re) Build after change in `src/main/java` in order for change to be tested
+* `Dockerfile.integrationtest` relies on built code and not on Maven central
+* Requires a deployable jar
+
+##### Configuration
+
+* Configuration in folder `src/test/java` and package `org.phoebus.olog.docker`, e.g. urls and port numbers, is coupled to files `Dockerfile.integrationtest` and `docker-compose-integrationtest.yml` (beside `src/main/resources/application.properties`)
+
+##### Debug
+
+* Docker containers can be inspected when debugging integration tests
+
+##### Performance
+
+* It may take a minute to run a test. This includes time to set up the test environment, perform the test and tear down the test environment. Setting up the test environment takes most of that time.
+* It may take additional time to run an integration test with code coverage.
diff --git a/src/test/resources/INTEGRATIONTEST_DOCKER_TUTORIAL.md b/src/test/resources/INTEGRATIONTEST_DOCKER_TUTORIAL.md
new file mode 100644
index 0000000..23cc654
--- /dev/null
+++ b/src/test/resources/INTEGRATIONTEST_DOCKER_TUTORIAL.md
@@ -0,0 +1,396 @@
+### About
+
+Describe ability to develop and run integration tests for Olog API with Docker.
+
+In other words, how to use `src/test/java` to test `src/main/java` with integration tests using Docker.
+
+##### Background
+
+Olog with Elasticsearch and MongDB together with the environment in which the applications run, is complex and usually heavily relied on by other applications and environments. Outside interface is to Olog but Olog, Elasticsearch and MongoDB go together. Therefore, there is need to test Olog, Elasticsearch and MongoDB together.
+
+It is possible to test Olog API by running Olog, Elasticsearch and MongoDB applications together as Docker containers and executing a series of requests and commands to test their behavior. This tutorial will show how it works and give examples.
+
+##### Content
+
+* [Prerequisites](#prerequisites)
+* [Examples](#examples)
+* [How it works - big picture](#how-it-works-big-picture)
+* [How it works - in detail](#how-it-works-in-detail)
+* [How to run](#how-to-run)
+* [Reference](#reference)
+
+### Prerequisites
+
+##### Tools
+
+* Docker - engine 18.06.0+ or later, compose 2.21.0 or later, compose file version 3.7 to be supported
+
+##### Dependencies
+
+* JUnit 5
+* Testcontainers
+
+##### Files
+
+* folder `src/test/java` and package `org.phoebus.olog.docker`
+* [docker-compose-integrationtest.yml](docker-compose-integrationtest.yml)
+* [Dockerfile.integrationtest](Dockerfile.integrationtest)
+
+### Examples
+
+##### Simple
+
+[OlogIT.java](src/test/java/org/phoebus/olog/docker/OlogIT.java)
+
+```
+@Test
+void ologUp()
+```
+
+Purpose
+* verify that Olog is up and running
+
+How
+* Http request (GET) is run towards Olog base url and response code is verified to be 200
+
+##### Medium
+
+[OlogPropertiesIT.java](src/test/java/org/phoebus/olog/docker/OlogPropertiesIT.java)
+
+```
+@Test
+void handleProperty()
+```
+
+Purpose
+* verify behavior for single property that include commands - list, create property, list, retrieve, delete (unauthorized), delete, list
+
+How
+* a series of Http requests (GET) and curl commands (POST, PUT, DELETE) are run towards the application to test behavior
+
+##### Complex
+
+[OlogLogsQueryIT.java](src/test/java/org/phoebus/olog/docker/OlogLogsQueryIT.java)
+
+```
+@Test
+void handleLogsQueryByPattern()
+```
+
+Purpose
+* set up test fixture - properties, tags, logbooks, logs associated with properties, tags & logbooks
+* query by pattern - search for a list of logs based on content, properties, tags, and/or logbooks
+* tear down test fixture - reverse to set up
+
+How
+* a series of Http requests (GET) and curl commands (POST, PUT, DELETE) are run towards the application to test behavior
+
+### How it works - big picture
+
+Integration tests are implemented in test class annotated with `@Testcontainers`. Test class starts a docker container for the application (Olog service) and other docker containers for elastic (Elasticsearch) and mongo (MongoDB) through `docker-compose-integrationtest.yml` and `Dockerfile.integrationtest` after which JUnit tests are run.
+
+```
+@Testcontainers
+class OlogIT {
+
+ @Container
+ public static final ComposeContainer ENVIRONMENT = ITUtil.defaultComposeContainers();
+
+ @Test
+ void ologUp() {
+ try {
+ String address = ITUtil.HTTP_IP_PORT_OLOG;
+ int responseCode = ITUtil.doGet(address);
+
+ assertEquals(HttpURLConnection.HTTP_OK, responseCode);
+ } catch (IOException e) {
+ fail();
+ }
+ }
+```
+
+Http requests (GET) and curl commands (POST, PUT, DELETE) are run towards the application to test behavior (read, list, query, create, update, remove) and replies are received and checked if content is as expected.
+
+There are tests for properties, tags, logbooks and logs separately and in combination.
+
+##### Note
+
+* Docker containers (Olog, Elasticsearch and MongoDB) are shared for tests within test class. Order in which tests are run is not known. Therefore, each test is to leave Olog, Elasticsearch and MongoDB in a clean state to not disturb other tests.
+
+### How it works - in detail
+
+##### Anatomy of an integration test
+
+```
+@Testcontainers
+class OlogPropertiesIT {
+
+ static Property[] default_properties;
+ static Property property_p1_owner_a_state_a_attributes;
+ static Property property_p1_owner_a_state_i_attributes;
+ static Attribute a1;
+
+ @Container
+ public static final ComposeContainer ENVIRONMENT = ITUtil.defaultComposeContainers();
+
+ @BeforeAll
+ public static void setupObjects() {
+ default_properties = new Property[] {new Property("resource", null, State.Active, new HashSet())};
+ default_properties[0].addAttributes(new Attribute("name", null, State.Active));
+ default_properties[0].addAttributes(new Attribute("file", null, State.Active));
+
+ a1 = new Attribute("a1", "v1", State.Active);
+
+ property_p1_owner_a_state_a_attributes = new Property("p1", "admin", State.Active, new HashSet());
+ property_p1_owner_a_state_a_attributes.addAttributes(a1);
+
+ property_p1_owner_a_state_i_attributes = new Property("p1", "admin", State.Inactive, new HashSet());
+ property_p1_owner_a_state_i_attributes.addAttributes(a1);
+ }
+
+ @AfterAll
+ public static void tearDownObjects() {
+ default_properties = null;
+
+ property_p1_owner_a_state_a_attributes = null;
+
+ property_p1_owner_a_state_i_attributes = null;
+
+ a1 = null;
+ }
+
+ /**
+ * Test {@link org.phoebus.olog.OlogResourceDescriptors#PROPERTY_RESOURCE_URI}.
+ */
+ @Test
+ void handleProperty() {
+ // what
+ // user with required role
+ // create property
+ // --------------------------------------------------------------------------------
+ // list, create, list/retrieve, remove (unauthorized), remove, retrieve/list
+ // --------------------------------------------------------------------------------
+ // x Retrieve a Property
+ // x List Properties
+ // x Create a Property
+ // Create Properties
+ // x Remove Property
+
+ try {
+ ITUtilProperties.assertListProperties(1, default_properties[0]);
+
+ ITUtilProperties.assertCreateProperty("/p1", property_p1_owner_a_state_a_attributes);
+
+ // refresh elastic indices
+ ITUtil.assertRefreshElasticIndices();
+
+ ITUtilProperties.assertListProperties(2,
+ property_p1_owner_a_state_a_attributes,
+ default_properties[0]);
+
+ ITUtilProperties.assertListProperties("?inactive=false", 2,
+ property_p1_owner_a_state_a_attributes,
+ default_properties[0]);
+
+ ITUtilProperties.assertListProperties("?inactive=true", 2,
+ property_p1_owner_a_state_a_attributes,
+ default_properties[0]);
+
+ ITUtilProperties.assertRetrieveProperty("/p1", property_p1_owner_a_state_a_attributes);
+
+ // check permissions
+ // ITUtilProperties.assertRemoveProperty(AuthorizationChoice.USER, "/p1", HttpURLConnection.HTTP_UNAUTHORIZED);
+
+ ITUtilProperties.assertRemoveProperty("/p1");
+
+ // refresh elastic indices
+ ITUtil.assertRefreshElasticIndices();
+
+ ITUtilProperties.assertRetrieveProperty("/p1", property_p1_owner_a_state_i_attributes);
+
+ ITUtilProperties.assertListProperties("?inactive=false", 1,
+ default_properties[0]);
+
+ ITUtilProperties.assertListProperties("?inactive=true", 2,
+ property_p1_owner_a_state_i_attributes,
+ default_properties[0]);
+
+ ITUtilProperties.assertListProperties(1, default_properties[0]);
+ } catch (Exception e) {
+ fail();
+ }
+ }
+```
+
+##### What happens at runtime
+
+The test environment is started with through test class annotated with `@Testcontainers` and constant `ENVIRONMENT` annotated with `@Container`. Containers are started (Ryuk, Olog, Elasticsearch, MongoDB). Then one time setup is run (method annotated with `@BeforeAll`), after which individual tests are run (methods annotated with `@Test`) after which one time tear down is run (method annotated with `@AfterAll`). Finally tasks are done and test class is closed.
+
+Note the extensive use of test utility classes (in more detail below) in which are shared code for common tasks.
+
+* authorization
+* serialization and deserialization of properties, tags, logbooks and logs
+* Http requests (GET) and curl commands (POST, PUT, DELETE) corresponding to endpoints in Olog API
+* assert response
+
+##### Examining `handleProperty`
+
+1. A GET request is made to Olog to list all properties and ensure that only default property is available.
+2. A PUT request is made to Olog to create the property listed by the path parameter. Request is made with ADMIN authority.
+3. A GET request is made to Elasticsearch to refresh indices.
+4. A GET request is made to Olog to list all properties and ensure there is one (given) property available with active status, beside default property.
+5. A GET request is made to Olog to list all properties not including inactive status and ensure there is one (given) property available with active status, beside default property.
+6. A GET request is made to Olog to list all properties including inactive status and ensure there is one (given) property available with active status, beside default property.
+7. A GET request is made to Olog to retrieve property with given name.
+8. A DELETE request is made to Olog to delete property. Request is made with ADMIN authority.
+9. A GET request is made to Elasticsearch to refresh indices.
+10. A GET request is made to Olog to retrieve property with given name.
+11. A GET request is made to Olog to list all properties not including inactive status and ensure that only default property is available.
+12. A GET request is made to Olog to list all properties including inactive status and ensure there is one (given) property available with inactive status, beside default property.
+13. A GET request is made to Olog to list all properties and ensure that only default property is available.
+
+
+* 1, 4, 5, 6, 11, 12, 13 - Request corresponds to PropertiesResource method
+
+```
+ @GetMapping
+ public Iterable findAll(@RequestParam(required=false) boolean inactive) {
+```
+
+* 2 - Request corresponds to PropertiesResource method
+
+```
+ @PutMapping("/{propertyName}")
+ public Property createProperty(@PathVariable String propertyName,
+ @RequestBody final Property property,
+ @AuthenticationPrincipal Principal principal) {
+```
+
+* 3, 9 - Request corresponds to ITUtil method
+
+```
+ static void assertRefreshElasticIndices() throws IOException {
+ String[] response = doGetJson(HTTP_IP_PORT_ELASTICSEARCH + "/_refresh");
+```
+
+* 7, 10 - Request corresponds to PropertiesResource method
+
+```
+ @GetMapping("/{propertyName}")
+ public Property findByTitle(@PathVariable String propertyName) {
+```
+
+* 8 - Request corresponds to PropertiesResource method
+
+```
+ @DeleteMapping("/{propertyName}")
+ public void deleteProperty (@PathVariable String propertyName) {
+```
+
+##### Test classes
+
+See `src/test/java` and `org.phoebus.olog.docker`.
+
+* files with suffix IT.java
+
+##### Test utilities
+
+See `src/test/java` and `org.phoebus.olog.docker`.
+
+* files with prefix ITTestFixture
+* files with prefix ITUtil
+
+##### Test utilities - example
+
+With the help of test utitilies, the tests themselves may be simplified and made more clear.
+
+```
+public class ITUtilLogs {
+
+ public static Log[] assertListLogs(int expectedEqual, Log... expected) {
+ return assertListLogs("", HttpURLConnection.HTTP_OK, expectedEqual, expectedEqual, expected);
+ }
+ public static Log[] assertListLogs(String queryString, int expectedEqual, Log... expected) {
+ return assertListLogs(queryString, HttpURLConnection.HTTP_OK, expectedEqual, expectedEqual, expected);
+ }
+
+ /**
+ * Utility method to return the list of all logs in the directory.
+ *
+ * @param queryString query string
+ * @param expectedResponseCode expected response code
+ * @param expectedGreaterThanOrEqual (if non-negative number) greater than or equal to this number of items
+ * @param expectedLessThanOrEqual (if non-negative number) less than or equal to this number of items
+ * @param expected expected response logs
+ * @return number of logs
+ */
+ public static Log[] assertListLogs(String queryString, int expectedResponseCode, int expectedGreaterThanOrEqual, int expectedLessThanOrEqual, Log... expected) {
+ try {
+ String[] response = null;
+ Log[] actual = null;
+
+ response = ITUtil.doGetJson(ITUtil.HTTP_IP_PORT_OLOG_LOGS + queryString);
+ ITUtil.assertResponseLength2Code(response, expectedResponseCode);
+ if (HttpURLConnection.HTTP_OK == expectedResponseCode) {
+ actual = mapper.readValue(response[1], Log[].class);
+ }
+
+ // expected number of items in list
+ // (if non-negative number)
+ // expectedGreaterThanOrEqual <= nbr of items <= expectedLessThanOrEqual
+ if (expectedGreaterThanOrEqual >= 0) {
+ assertTrue(actual.length >= expectedGreaterThanOrEqual);
+ }
+ if (expectedLessThanOrEqual >= 0) {
+ assertTrue(actual.length <= expectedLessThanOrEqual);
+ }
+
+ // expected content
+ if (expected != null && expected.length > 0) {
+ ITUtil.assertEqualsLogs(actual, expected);
+ }
+
+ return actual;
+ } catch (IOException e) {
+ fail();
+ } catch (Exception e) {
+ fail();
+ }
+ return null;
+ }
+```
+
+Above methods can be used like shown below.
+
+```
+@Testcontainers
+public class OlogLogsQueryIT {
+
+ @Test
+ void handleLogsQueryByPattern() {
+
+ ITUtilLogs.assertListLogs("?desc", 60);
+ ITUtilLogs.assertListLogs("?desc=asdf", 0);
+ ITUtilLogs.assertListLogs("?desc=Initial", 2);
+
+```
+
+##### Note
+
+* (Re) Build after change in `src/main/java` is needed in order for change to be tested as `Dockerfile.integrationtest` relies on built code.
+* Configuration in folder `src/test/java` and package `org.phoebus.olog.docker`, e.g. urls and port numbers, is coupled to files `Dockerfile.integrationtest` and `docker-compose-integrationtest.yml` (beside `src/main/resources/application.properties`).
+* Both positive and negative tests are important to ensure validation works as expected.
+
+### How to run
+
+See [How to run Integration test with Docker](INTEGRATIONTEST_DOCKER_RUN.md).
+
+### Reference
+
+##### Olog
+
+* [Olog Service Documentation](https://olog.readthedocs.io/en/latest/)
+
+##### Testcontainers
+
+* [Testcontainers](https://testcontainers.com/)