/testsuite/server-technical-testsuite/src/test/java/org/marvelution/jji/data/access/model/v3/T13_CopyAutomationAppDataIT.java
Java | 225 lines | 188 code | 20 blank | 17 comment | 0 complexity | f8d963d552ac842bd3924f6f5be2cc86 MD5 | raw file
- /*
- * Copyright (c) 2012-present Marvelution B.V.
- *
- * 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.marvelution.jji.data.access.model.v3;
- import java.time.*;
- import org.marvelution.jji.api.*;
- import org.marvelution.jji.api.utils.*;
- import org.marvelution.jji.automation.*;
- import org.marvelution.jji.automation.api.execution.*;
- import org.marvelution.jji.data.access.*;
- import org.marvelution.jji.data.access.model.*;
- import org.marvelution.jji.test.data.*;
- import org.marvelution.jji.test.data.converters.*;
- import org.marvelution.testing.*;
- import org.marvelution.testing.inject.*;
- import com.atlassian.pocketknife.api.querydsl.*;
- import com.atlassian.pocketknife.api.querydsl.util.*;
- import com.google.inject.Module;
- import com.google.inject.*;
- import net.java.ao.*;
- import net.java.ao.builder.*;
- import net.java.ao.schema.*;
- import net.java.ao.test.jdbc.*;
- import org.junit.jupiter.api.*;
- import org.junit.jupiter.api.extension.*;
- import static org.marvelution.jji.data.access.model.v3.T13_CopyAutomationAppData.*;
- import static org.assertj.core.api.Assertions.*;
- import static org.mockito.Mockito.*;
- @ExtendWith({ ActiveObjectsExtension.class, InjectorExtension.class })
- @Data(T13_CopyAutomationAppDataIT.AutomationAppTablesLoader.class)
- public class T13_CopyAutomationAppDataIT
- extends TestSupport
- implements Module
- {
- private final ActiveObjectsExtension.EntityManagerContext entityManagerContext;
- @Inject
- private DatabaseAccessor databaseAccessor;
- @Inject
- private ServerPersistedRuleDAO ruleDAO;
- @Inject
- private ServerPersistedRuleExecutionResultDAO resultDAO;
- @Inject
- private T13_CopyAutomationAppData underTest;
- public T13_CopyAutomationAppDataIT(ActiveObjectsExtension.EntityManagerContext entityManagerContext)
- {
- this.entityManagerContext = entityManagerContext;
- }
- @Override
- public void configure(Binder binder)
- {
- binder.install(new DataAccessModule(entityManagerContext));
- binder.bind(T13_CopyAutomationAppData.class).in(Singleton.class);
- binder.bind(AddonHelper.class).toInstance(mock(AddonHelper.class));
- binder.bind(ReloadableRulesEngine.class).toInstance(mock(ReloadableRulesEngine.class));
- }
- @Test
- void testUpgrade_NoExistingData()
- {
- assertThat(ruleDAO.getRules()).isEmpty();
- underTest.doUpgrade();
- assertThat(ruleDAO.getRules()).isEmpty();
- }
- @Test
- void testUpgrade_ExistingData()
- {
- loadAutomationAppData();
- assertThat(ruleDAO.getRules()).isEmpty();
- underTest.doUpgrade();
- assertThat(ruleDAO.getRules()).hasSize(2)
- .extracting(PersistedRule::getId, PersistedRule::getName, PersistedRule::isEnabled, PersistedRule::getDescription)
- .containsOnly(tuple("rule-1", "Rule 1", true, "Test Rule 1"), tuple("rule-2", "Rule 2", false, "Test Rule 2"));
- assertThat(resultDAO.getResults("rule-1", 0, 100)).hasSize(2);
- assertThat(resultDAO.getResults("rule-2", 0, 100)).hasSize(1);
- }
- public void loadAutomationAppData()
- {
- PersistedRuleTable ruleTable = new PersistedRuleTable(OLD_NAMESPACE);
- RuleExecutionResultTable resultTable = new RuleExecutionResultTable(OLD_NAMESPACE);
- RuleExecutionQueueTable queueTable = new RuleExecutionQueueTable(OLD_NAMESPACE);
- databaseAccessor.runInTransaction(conn -> {
- conn.insert(ruleTable)
- .set(ruleTable.id(), "rule-1")
- .set(ruleTable.name(), "Rule 1")
- .set(ruleTable.enabled(), true)
- .set(ruleTable.description(), "Test Rule 1")
- .set(ruleTable.whenJson(), "{\"handlerId\":\"build.synchronized\",\"configuration\":{}}")
- .set(ruleTable.ifJson(), "[{\"conditionId\":\"build.of.job\",\"configuration\":{\"jobIds\":\"job-1\"}}]")
- .set(ruleTable.thenJson(), "[{\"actionId\":\"transition.issue\",\"configuration\":{\"target_status\":\"10000\"," +
- "\"transition_match_pattern\":\"\",\"issue_selector\":\"linkedToBuild\"," +
- "\"issue_selector_expression\":\"\",\"comment\":\"\",\"advanced_fields\":\"\"}}]")
- .addBatch()
- .set(ruleTable.id(), "rule-2")
- .set(ruleTable.name(), "Rule 2")
- .set(ruleTable.enabled(), false)
- .set(ruleTable.description(), "Test Rule 2")
- .set(ruleTable.whenJson(), "{\"handlerId\":\"build.synchronized\",\"configuration\":{}}")
- .set(ruleTable.ifJson(), (String) null)
- .set(ruleTable.thenJson(), "[]")
- .addBatch()
- .execute();
- conn.insert(resultTable)
- .set(resultTable.id(), "result-1")
- .set(resultTable.ruleId(), "rule-2")
- .set(resultTable.executionTimestamp(), TimeUtils.toMillis(LocalDateTime.now()))
- .set(resultTable.durationInMillis(), TimeUtils.toMillis(Duration.ofMillis(100)))
- .set(resultTable.eventJson(), "{\"handlerId\":\"build.synchronized\",\"eventType\":\"org.marvelution.jji.events" +
- ".BuildSynchronizedEvent\",\"event\":{\"syncable\":{\"id\":\"8620460e6ed34a4ba41e142f5d5c06ed\"," +
- "\"job\":{\"id\":\"c77d997b73dd4503b783b0c42e3ef03f\",\"site\":{\"id\":\"bcf0479d2cc04ce29272ce61a428d682\"," +
- "\"name\":\"Local\",\"sharedSecret\":\"#~OBFUSCATED~#\",\"type\":\"JENKINS\"," +
- "\"rpcUrl\":\"https://6f56da141706.eu.ngrok.io/\",\"useCrumbs\":true,\"jenkinsPluginInstalled\":true," +
- "\"registrationComplete\":true,\"autoLinkNewJobs\":true,\"hasJobs\":false,\"hasDeletedJobs\":false," +
- "\"firewalled\":true},\"name\":\"testing\",\"fullName\":\"testing\",\"urlName\":\"testing\"," +
- "\"displayUrl\":\"https://6f56da141706.eu.ngrok.io/job/testing/\",\"lastBuild\":1,\"oldestBuild\":-1," +
- "\"linked\":true,\"deleted\":false},\"number\":1,\"displayUrl\":\"https://6f56da141706.eu.ngrok" +
- ".io/job/testing/1/\",\"deleted\":false,\"cause\":\"Started by user admin@example.com\",\"building\":false," +
- "\"result\":\"SUCCESS\",\"builtOn\":\"master\",\"duration\":100,\"timestamp\":1599490625972,\"branches\":[]," +
- "\"changeSet\":[],\"deploymentEnvironments\":[]},\"timestamp\":{\"date\":{\"year\":2020,\"month\":9," +
- "\"day\":7},\"time\":{\"hour\":14,\"minute\":57,\"second\":7,\"nano\":87595000}}}}")
- .set(resultTable.conditionResultsJson(), "[]")
- .set(resultTable.actionResultsJson(), "[]")
- .addBatch()
- .set(resultTable.id(), "result-2")
- .set(resultTable.ruleId(), "rule-1")
- .set(resultTable.executionTimestamp(), TimeUtils.toMillis(LocalDateTime.now()))
- .set(resultTable.durationInMillis(), TimeUtils.toMillis(Duration.ofMillis(100)))
- .set(resultTable.eventJson(), "{\"handlerId\":\"build.synchronized\",\"eventType\":\"org.marvelution.jji.events" +
- ".BuildSynchronizedEvent\",\"event\":{\"syncable\":{\"id\":\"8620460e6ed34a4ba41e142f5d5c06ed\"," +
- "\"job\":{\"id\":\"c77d997b73dd4503b783b0c42e3ef03f\",\"site\":{\"id\":\"bcf0479d2cc04ce29272ce61a428d682\"," +
- "\"name\":\"Local\",\"sharedSecret\":\"#~OBFUSCATED~#\",\"type\":\"JENKINS\"," +
- "\"rpcUrl\":\"https://6f56da141706.eu.ngrok.io/\",\"useCrumbs\":true,\"jenkinsPluginInstalled\":true," +
- "\"registrationComplete\":true,\"autoLinkNewJobs\":true,\"hasJobs\":false,\"hasDeletedJobs\":false," +
- "\"firewalled\":true},\"name\":\"testing\",\"fullName\":\"testing\",\"urlName\":\"testing\"," +
- "\"displayUrl\":\"https://6f56da141706.eu.ngrok.io/job/testing/\",\"lastBuild\":1,\"oldestBuild\":-1," +
- "\"linked\":true,\"deleted\":false},\"number\":1,\"displayUrl\":\"https://6f56da141706.eu.ngrok" +
- ".io/job/testing/1/\",\"deleted\":false,\"cause\":\"Started by user admin@example.com\",\"building\":false," +
- "\"result\":\"SUCCESS\",\"builtOn\":\"master\",\"duration\":100,\"timestamp\":1599490625972,\"branches\":[]," +
- "\"changeSet\":[],\"deploymentEnvironments\":[]},\"timestamp\":{\"date\":{\"year\":2020,\"month\":9," +
- "\"day\":7},\"time\":{\"hour\":14,\"minute\":57,\"second\":7,\"nano\":87595000}}}}")
- .set(resultTable.conditionResultsJson(), "[{\"conditionId\":\"build.of.job\",\"duration\":2,\"matches\":false}]")
- .set(resultTable.actionResultsJson(), "[]")
- .addBatch()
- .set(resultTable.id(), "result-3")
- .set(resultTable.ruleId(), "rule-1")
- .set(resultTable.executionTimestamp(), TimeUtils.toMillis(LocalDateTime.now()))
- .set(resultTable.durationInMillis(), TimeUtils.toMillis(Duration.ofMillis(100)))
- .set(resultTable.eventJson(), "{\"handlerId\":\"build.synchronized\",\"eventType\":\"org.marvelution.jji.events" +
- ".BuildSynchronizedEvent\",\"event\":{\"syncable\":{\"id\":\"8620460e6ed34a4ba41e142f5d5c06ed\"," +
- "\"job\":{\"id\":\"job-1\",\"site\":{\"id\":\"bcf0479d2cc04ce29272ce61a428d682\",\"name\":\"Local\"," +
- "\"sharedSecret\":\"#~OBFUSCATED~#\",\"type\":\"JENKINS\",\"rpcUrl\":\"https://6f56da141706.eu.ngrok.io/\"," +
- "\"useCrumbs\":true,\"jenkinsPluginInstalled\":true,\"registrationComplete\":true,\"autoLinkNewJobs\":true," +
- "\"hasJobs\":false,\"hasDeletedJobs\":false,\"firewalled\":true},\"name\":\"testing\"," +
- "\"fullName\":\"testing\",\"urlName\":\"testing\",\"displayUrl\":\"https://6f56da141706.eu.ngrok" +
- ".io/job/testing/\",\"lastBuild\":1,\"oldestBuild\":-1,\"linked\":true,\"deleted\":false},\"number\":1," +
- "\"displayUrl\":\"https://6f56da141706.eu.ngrok.io/job/testing/1/\",\"deleted\":false,\"cause\":\"Started by " +
- "user admin@example.com\",\"building\":false,\"result\":\"SUCCESS\",\"builtOn\":\"master\",\"duration\":100," +
- "\"timestamp\":1599490625972,\"branches\":[],\"changeSet\":[],\"deploymentEnvironments\":[]}," +
- "\"timestamp\":{\"date\":{\"year\":2020,\"month\":9,\"day\":7},\"time\":{\"hour\":14,\"minute\":57," +
- "\"second\":7,\"nano\":87595000}}}}")
- .set(resultTable.conditionResultsJson(), "[{\"conditionId\":\"build.of.job\",\"duration\":2,\"matches\":true}]")
- .set(resultTable.actionResultsJson(), "[{\"actionId\":\"transition.issue\",\"duration\":2813,\"state\":\"SUCCESS\"," +
- "\"messages\":[{\"message\":\"rule.action.transition.issue.transitioned.succeeded\"," +
- "\"arguments\":[\"DEV-15\",\"To Do\"]},{\"message\":\"rule.action.transition.issue.transitioned.succeeded\"," +
- "\"arguments\":[\"DEV-12\",\"To Do\"]},{\"message\":\"rule.action.transition.issue.transitioned.succeeded\"," +
- "\"arguments\":[\"DEV-11\",\"To Do\"]},{\"message\":\"rule.action.transition.issue.transitioned.succeeded\"," +
- "\"arguments\":[\"DEV-14\",\"To Do\"]},{\"message\":\"rule.action.transition.issue.transitioned.succeeded\"," +
- "\"arguments\":[\"DEV-13\",\"To Do\"]}]}]")
- .addBatch()
- .execute();
- return null;
- }, OnRollback.NOOP);
- }
- public static class AutomationAppTablesLoader
- extends ModelDatabaseUpdater
- {
- @Override
- public void update(EntityManager entityManager)
- throws Exception
- {
- // Migrate Integration entities
- super.update(entityManager);
- // Migrate Automation entities
- SchemaGenerator.migrate(entityManager.getProvider(), entityManager.getSchemaConfiguration(),
- getNameConverters(entityManager.getNameConverters()), false, PersistedRuleEntity.class,
- PersistedRuleExecutionResultEntity.class, RuleExecutionQueueEntity.class);
- }
- private NameConverters getNameConverters(NameConverters nameConverters)
- {
- return new SimpleNameConverters(new PrefixesTableNameConverter(OLD_NAMESPACE), nameConverters.getFieldNameConverter(),
- nameConverters.getSequenceNameConverter(), nameConverters.getTriggerNameConverter(),
- nameConverters.getIndexNameConverter(), nameConverters.getUniqueNameConverter());
- }
- }
- }