|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | + * or more contributor license agreements. See the NOTICE file |
| 4 | + * distributed with this work for additional information |
| 5 | + * regarding copyright ownership. The ASF licenses this file |
| 6 | + * to you under the Apache License, Version 2.0 (the |
| 7 | + * "License"); you may not use this file except in compliance |
| 8 | + * with the License. You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, |
| 13 | + * software distributed under the License is distributed on an |
| 14 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | + * KIND, either express or implied. See the License for the |
| 16 | + * specific language governing permissions and limitations |
| 17 | + * under the License. |
| 18 | + */ |
| 19 | +package org.commonwl.view.workflow; |
| 20 | + |
| 21 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
| 22 | +import static org.junit.jupiter.api.Assertions.assertNotNull; |
| 23 | +import static org.junit.jupiter.api.Assertions.assertNull; |
| 24 | + |
| 25 | +import java.util.List; |
| 26 | +import org.commonwl.view.git.GitDetails; |
| 27 | +import org.junit.jupiter.api.Test; |
| 28 | +import org.springframework.beans.factory.annotation.Autowired; |
| 29 | +import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase; |
| 30 | +import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; |
| 31 | +import org.springframework.test.context.ContextConfiguration; |
| 32 | +import org.springframework.test.context.TestPropertySource; |
| 33 | +import org.springframework.transaction.annotation.Propagation; |
| 34 | +import org.springframework.transaction.annotation.Transactional; |
| 35 | + |
| 36 | +@TestPropertySource(locations = "classpath:it-application.properties") |
| 37 | +@DataJpaTest(showSql = true) |
| 38 | +@Transactional(propagation = Propagation.NOT_SUPPORTED) |
| 39 | +@ContextConfiguration(initializers = PostgreSQLContextInitializer.class) |
| 40 | +@AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE) |
| 41 | +public class WorkflowRepositoryTest { |
| 42 | + |
| 43 | + @Autowired WorkflowRepository repository; |
| 44 | + |
| 45 | + @Test |
| 46 | + public void deleteQueuedWorkflowByRetrievedFromTest() { |
| 47 | + |
| 48 | + assertNotNull(repository); |
| 49 | + |
| 50 | + // create stub workflow |
| 51 | + GitDetails gitDetails = |
| 52 | + new GitDetails("https://github.com/common-workflow-language/cwlviewer/", "main", "/"); |
| 53 | + gitDetails.setPackedId("test_packedId"); |
| 54 | + |
| 55 | + Workflow workflow = new Workflow(); |
| 56 | + workflow.setRetrievedFrom(gitDetails); |
| 57 | + |
| 58 | + // save workflow |
| 59 | + repository.saveAndFlush(workflow); |
| 60 | + |
| 61 | + List<Workflow> all = repository.findAll(); |
| 62 | + assertNotNull(all); |
| 63 | + assertEquals(1, all.size()); |
| 64 | + |
| 65 | + // retrieve saved workflow by git details |
| 66 | + Workflow retrievedQueuedWorkflowAfterSave = |
| 67 | + repository.findByRetrievedFrom(workflow.getRetrievedFrom()); |
| 68 | + assertNotNull(retrievedQueuedWorkflowAfterSave); |
| 69 | + |
| 70 | + // delete saved workflow by git details |
| 71 | + repository.delete(workflow); |
| 72 | + |
| 73 | + // retrieve deleted queued workflow by workflow git details |
| 74 | + Workflow retrievedQueuedWorkflowAfterDelete = |
| 75 | + repository.findByRetrievedFrom(workflow.getRetrievedFrom()); |
| 76 | + assertNull(retrievedQueuedWorkflowAfterDelete); |
| 77 | + } |
| 78 | +} |
0 commit comments