-
Notifications
You must be signed in to change notification settings - Fork 205
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8318 from shawkins/master
chore(dv) ENTESB-13076 adding a hook to reset dv
- Loading branch information
Showing
8 changed files
with
156 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
app/dv/src/main/java/io/syndesis/dv/server/endpoint/TestSupportHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
* Copyright (C) 2016 Red Hat, Inc. | ||
* | ||
* 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 io.syndesis.dv.server.endpoint; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import io.swagger.annotations.Api; | ||
import io.swagger.annotations.ApiOperation; | ||
import io.swagger.annotations.ApiResponse; | ||
import io.swagger.annotations.ApiResponses; | ||
import io.syndesis.dv.model.DataVirtualization; | ||
import io.syndesis.dv.server.DvService; | ||
import io.syndesis.dv.server.V1Constants; | ||
|
||
@RestController | ||
@ConditionalOnProperty(value = "endpoints.test_support.enabled") | ||
@RequestMapping( V1Constants.APP_PATH+V1Constants.FS+V1Constants.TEST_SUPPORT ) | ||
@Api( tags = {V1Constants.TEST_SUPPORT} ) | ||
public class TestSupportHandler extends DvService { | ||
|
||
@Autowired | ||
private DataVirtualizationService dataVirtualizationService; | ||
|
||
@GetMapping(value = "/reset-db") | ||
@ApiOperation(value = "Reset the persistent and running state.") | ||
@ApiResponses(value = { | ||
@ApiResponse(code = 400, message = "An error has occurred.") | ||
}) | ||
public void resetDBToDefault() throws Exception { | ||
Iterable<? extends DataVirtualization> virtualizations = repositoryManager.runInTransaction(true, ()->{ | ||
return repositoryManager.findDataVirtualizations(); | ||
}); | ||
|
||
for (DataVirtualization dv : virtualizations) { | ||
try { | ||
dataVirtualizationService.deletePublishedVirtualization(dv.getName()); | ||
dataVirtualizationService.deleteDataVirtualization(dv.getName()); | ||
} catch (Exception e) { | ||
LOGGER.info("Could not delete virtualization %s", e, dv.getName()); //$NON-NLS-1$ | ||
} | ||
} | ||
} | ||
|
||
} |
69 changes: 69 additions & 0 deletions
69
app/dv/src/test/java/io/syndesis/dv/server/endpoint/IntegrationResetTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
* Copyright (C) 2016 Red Hat, Inc. | ||
* | ||
* 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 io.syndesis.dv.server.endpoint; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
import java.util.List; | ||
|
||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; | ||
import org.springframework.boot.test.web.client.TestRestTemplate; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.test.context.ContextConfiguration; | ||
import org.springframework.test.context.junit4.SpringRunner; | ||
|
||
import io.syndesis.dv.server.Application; | ||
import io.syndesis.dv.server.endpoint.IntegrationTest.IntegrationTestConfiguration; | ||
|
||
@RunWith(SpringRunner.class) | ||
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) | ||
@ContextConfiguration(classes = {IntegrationTestConfiguration.class, Application.class}) | ||
@SuppressWarnings("nls") | ||
public class IntegrationResetTest { | ||
|
||
@Autowired | ||
private TestRestTemplate restTemplate; | ||
|
||
@Test | ||
public void testReset() throws Exception { | ||
RestDataVirtualization rdv = new RestDataVirtualization(); | ||
String dvName = "testPublish"; | ||
rdv.setName(dvName); | ||
rdv.setDescription("description"); | ||
|
||
ResponseEntity<String> response = restTemplate.postForEntity( | ||
"/v1/virtualizations", rdv, String.class); | ||
assertEquals(HttpStatus.OK, response.getStatusCode()); | ||
|
||
ResponseEntity<List> virts = restTemplate.getForEntity("/v1/virtualizations", List.class); | ||
assertEquals(HttpStatus.OK, virts.getStatusCode()); | ||
assertEquals(1, virts.getBody().size()); | ||
|
||
ResponseEntity<String> resetResponse = restTemplate.getForEntity("/v1/test-support/reset-db", String.class); | ||
assertEquals(HttpStatus.OK, resetResponse.getStatusCode()); | ||
|
||
virts = restTemplate.getForEntity("/v1/virtualizations", List.class); | ||
assertEquals(HttpStatus.OK, virts.getStatusCode()); | ||
assertEquals(0, virts.getBody().size()); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.