Skip to content

Commit

Permalink
Add Dev UI integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Christopher-Chianelli committed Jul 7, 2021
1 parent a26c650 commit 66cd5ff
Show file tree
Hide file tree
Showing 10 changed files with 560 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/target
/local

# Eclipse, Netbeans and IntelliJ files
/.*
!.gitignore
/nbproject
/*.ipr
/*.iws
/*.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.optaplanner</groupId>
<artifactId>optaplanner-quarkus-parent</artifactId>
<version>8.9.0-SNAPSHOT</version>
</parent>

<artifactId>optaplanner-quarkus-devui-integration-test</artifactId>
<name>OptaPlanner Quarkus - Dev UI Integration tests</name>
<description>Quarkus Dev UI integration tests for OptaPlanner</description>

<properties>
<java.module.name>org.optaplanner.quarkus</java.module.name>
</properties>

<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-arc</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy</artifactId>
</dependency>
<dependency>
<groupId>org.optaplanner</groupId>
<artifactId>optaplanner-quarkus</artifactId>
</dependency>

<!-- test dependencies -->
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5-internal</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>build</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<!-- Transitive dependencies through quarkus are expected in this module. -->
<id>analyze-only</id>
<phase>none</phase>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</plugins>
</build>

<profiles>
<profile>
<id>native</id>
<activation>
<property>
<name>native</name>
</property>
</activation>
<build>
<plugins>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<configuration>
<skip>false</skip>
</configuration>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
<configuration>
<systemPropertyVariables>
<native.image.path>${project.build.directory}/${project.build.finalName}-runner</native.image.path>
</systemPropertyVariables>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<properties>
<quarkus.package.type>native</quarkus.package.type>
</properties>
</profile>
</profiles>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Copyright 2021 Red Hat, Inc. and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.optaplanner.quarkus.it.devui;

import java.util.Arrays;
import java.util.concurrent.ExecutionException;

import javax.inject.Inject;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

import org.optaplanner.core.api.solver.SolverJob;
import org.optaplanner.core.api.solver.SolverManager;
import org.optaplanner.quarkus.it.devui.domain.TestdataStringLengthShadowEntity;
import org.optaplanner.quarkus.it.devui.domain.TestdataStringLengthShadowSolution;

@Path("/optaplanner/test")
public class OptaPlannerTestResource {

@Inject
SolverManager<TestdataStringLengthShadowSolution, Long> solverManager;

@POST
@Path("/solver-factory")
@Produces(MediaType.TEXT_PLAIN)
public String solveWithSolverFactory() {
TestdataStringLengthShadowSolution planningProblem = new TestdataStringLengthShadowSolution();
planningProblem.setEntityList(Arrays.asList(
new TestdataStringLengthShadowEntity(),
new TestdataStringLengthShadowEntity()));
planningProblem.setValueList(Arrays.asList("a", "bb", "ccc"));
SolverJob<TestdataStringLengthShadowSolution, Long> solverJob = solverManager.solve(1L, planningProblem);
try {
return solverJob.getFinalBestSolution().getScore().toString();
} catch (InterruptedException | ExecutionException e) {
throw new IllegalStateException("Solving failed.", e);
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* Copyright 2021 Red Hat, Inc. and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.optaplanner.quarkus.it.devui.domain;

import org.optaplanner.core.api.domain.variable.VariableListener;
import org.optaplanner.core.api.score.director.ScoreDirector;

public class StringLengthVariableListener
implements VariableListener<TestdataStringLengthShadowSolution, TestdataStringLengthShadowEntity> {

@Override
public void beforeEntityAdded(ScoreDirector<TestdataStringLengthShadowSolution> scoreDirector,
TestdataStringLengthShadowEntity entity) {
/* Nothing to do */
}

@Override
public void afterEntityAdded(ScoreDirector<TestdataStringLengthShadowSolution> scoreDirector,
TestdataStringLengthShadowEntity entity) {
/* Nothing to do */
}

@Override
public void beforeVariableChanged(ScoreDirector<TestdataStringLengthShadowSolution> scoreDirector,
TestdataStringLengthShadowEntity entity) {
/* Nothing to do */
}

@Override
public void afterVariableChanged(ScoreDirector<TestdataStringLengthShadowSolution> scoreDirector,
TestdataStringLengthShadowEntity entity) {
int oldLength = (entity.getLength() != null) ? entity.getLength() : 0;
int newLength = getLength(entity.getValue());
if (oldLength != newLength) {
scoreDirector.beforeVariableChanged(entity, "length");
entity.setLength(getLength(entity.getValue()));
scoreDirector.afterVariableChanged(entity, "length");
}
}

@Override
public void beforeEntityRemoved(ScoreDirector<TestdataStringLengthShadowSolution> scoreDirector,
TestdataStringLengthShadowEntity entity) {
/* Nothing to do */
}

@Override
public void afterEntityRemoved(ScoreDirector<TestdataStringLengthShadowSolution> scoreDirector,
TestdataStringLengthShadowEntity entity) {
/* Nothing to do */
}

private static int getLength(String value) {
if (value != null) {
return value.length();
} else {
return 0;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* Copyright 2021 Red Hat, Inc. and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.optaplanner.quarkus.it.devui.domain;

import org.optaplanner.core.api.domain.entity.PlanningEntity;
import org.optaplanner.core.api.domain.variable.CustomShadowVariable;
import org.optaplanner.core.api.domain.variable.PlanningVariable;
import org.optaplanner.core.api.domain.variable.PlanningVariableReference;

@PlanningEntity
public class TestdataStringLengthShadowEntity {

@PlanningVariable(valueRangeProviderRefs = "valueRange")
private String value;

@CustomShadowVariable(variableListenerClass = StringLengthVariableListener.class,
sources = {
@PlanningVariableReference(entityClass = TestdataStringLengthShadowEntity.class,
variableName = "value")
})
private Integer length;

// ************************************************************************
// Getters/setters
// ************************************************************************

public String getValue() {
return value;
}

public void setValue(String value) {
this.value = value;
}

public Integer getLength() {
return length;
}

public void setLength(Integer length) {
this.length = length;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* Copyright 2021 Red Hat, Inc. and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.optaplanner.quarkus.it.devui.domain;

import java.util.List;

import org.optaplanner.core.api.domain.solution.PlanningEntityCollectionProperty;
import org.optaplanner.core.api.domain.solution.PlanningScore;
import org.optaplanner.core.api.domain.solution.PlanningSolution;
import org.optaplanner.core.api.domain.valuerange.ValueRangeProvider;
import org.optaplanner.core.api.score.buildin.hardsoft.HardSoftScore;

@PlanningSolution
public class TestdataStringLengthShadowSolution {

@ValueRangeProvider(id = "valueRange")
private List<String> valueList;
@PlanningEntityCollectionProperty
private List<TestdataStringLengthShadowEntity> entityList;

@PlanningScore
private HardSoftScore score;

// ************************************************************************
// Getters/setters
// ************************************************************************

public List<String> getValueList() {
return valueList;
}

public void setValueList(List<String> valueList) {
this.valueList = valueList;
}

public List<TestdataStringLengthShadowEntity> getEntityList() {
return entityList;
}

public void setEntityList(List<TestdataStringLengthShadowEntity> entityList) {
this.entityList = entityList;
}

public HardSoftScore getScore() {
return score;
}

public void setScore(HardSoftScore score) {
this.score = score;
}
}
Loading

0 comments on commit 66cd5ff

Please sign in to comment.