This repository has been archived by the owner on Mar 29, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 314
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added tests for serialization of FileInfoResource
- Loading branch information
Showing
8 changed files
with
260 additions
and
14 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
62 changes: 62 additions & 0 deletions
62
.../test/java/org/springframework/batch/admin/domain/FileInfoResourceSerializationTests.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,62 @@ | ||
/* | ||
* Copyright 2014 the original author or authors. | ||
* | ||
* 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.springframework.batch.admin.domain; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
import java.text.DateFormat; | ||
import java.text.SimpleDateFormat; | ||
import java.util.Date; | ||
|
||
import org.springframework.test.util.JsonPathExpectationsHelper; | ||
|
||
/** | ||
* @author Michael Minella | ||
*/ | ||
public class FileInfoResourceSerializationTests extends AbstractSerializationTests<FileInfoResource> { | ||
|
||
private String timestamp = formatter.format(new Date()); | ||
|
||
private static DateFormat formatter = new SimpleDateFormat(""); | ||
|
||
@Override | ||
public void assertJson(String json) throws Exception { | ||
new JsonPathExpectationsHelper("$.timestamp").assertValue(json, timestamp); | ||
new JsonPathExpectationsHelper("$.path").assertValue(json, "file://foo/bar/baz.txt"); | ||
new JsonPathExpectationsHelper("$.shortPath").assertValue(json, "foo/bar/baz.txt"); | ||
new JsonPathExpectationsHelper("$.local").assertValue(json, true); | ||
} | ||
|
||
@Override | ||
public void assertObject(FileInfoResource fileInfoResource) throws Exception { | ||
assertEquals(timestamp, fileInfoResource.getTimestamp()); | ||
assertEquals("file://foo/bar/baz.txt", fileInfoResource.getPath()); | ||
assertEquals("foo/bar/baz.txt", fileInfoResource.getShortPath()); | ||
assertTrue(fileInfoResource.isLocal()); | ||
} | ||
|
||
@Override | ||
public FileInfoResource getSerializationValue() { | ||
FileInfoResource resource = | ||
new FileInfoResource(timestamp, | ||
"file://foo/bar/baz.txt", | ||
"foo/bar/baz.txt", | ||
true, | ||
0); | ||
return resource; | ||
} | ||
} |
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
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
105 changes: 105 additions & 0 deletions
105
...c/test/java/org/springframework/batch/admin/web/BatchFilesControllerIntegrationTests.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,105 @@ | ||
/* | ||
* Copyright 2013-2015 the original author or authors. | ||
* | ||
* 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.springframework.batch.admin.web; | ||
|
||
import static org.hamcrest.Matchers.contains; | ||
import static org.hamcrest.Matchers.equalTo; | ||
import static org.mockito.Mockito.when; | ||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete; | ||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.Date; | ||
import java.util.List; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
import org.springframework.batch.admin.service.FileInfo; | ||
import org.springframework.batch.admin.service.FileService; | ||
import org.springframework.batch.core.ExitStatus; | ||
import org.springframework.batch.core.JobExecution; | ||
import org.springframework.batch.core.JobParametersBuilder; | ||
import org.springframework.batch.core.StepExecution; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.test.context.ContextConfiguration; | ||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; | ||
import org.springframework.test.context.web.WebAppConfiguration; | ||
|
||
/** | ||
* Tests REST compliance of {@link BatchJobInstancesController} endpoints. | ||
* | ||
* @author Ilayaperumal Gopinathan | ||
* @author Michael Minella | ||
*/ | ||
@RunWith(SpringJUnit4ClassRunner.class) | ||
@ContextConfiguration(classes = {TestDependencies.class, RestConfiguration.class}) | ||
@WebAppConfiguration | ||
public class BatchFilesControllerIntegrationTests extends AbstractControllerIntegrationTest { | ||
|
||
@Autowired | ||
private FileService fileService; | ||
|
||
@Before | ||
public void before() throws Exception { | ||
Date startTime = new Date(); | ||
Date endTime = new Date(); | ||
JobExecution execution = new JobExecution(3L, | ||
new JobParametersBuilder().addString("foo", "bar").addLong("foo2", 0L).toJobParameters()); | ||
execution.setExitStatus(ExitStatus.COMPLETED); | ||
execution.setStartTime(startTime); | ||
execution.setEndTime(endTime); | ||
execution.setLastUpdated(new Date()); | ||
|
||
StepExecution stepExecution = new StepExecution("s1", execution); | ||
stepExecution.setLastUpdated(new Date()); | ||
stepExecution.setId(1l); | ||
execution.addStepExecutions(Collections.singletonList(stepExecution)); | ||
} | ||
|
||
@Test | ||
public void testList() throws Exception { | ||
List<FileInfo> files = new ArrayList<FileInfo>(); | ||
files.add(new FileInfo("foo.txt", "sometimestamp", true, 0)); | ||
files.add(new FileInfo("bar/foo.txt", "anothertimestamp", false, 0)); | ||
files.add(new FileInfo("bar/baz.txt", "lasttimestamp", true, 0)); | ||
|
||
when(fileService.getFiles(0, 10)).thenReturn(files); | ||
|
||
mockMvc.perform( | ||
get("/batch/files").param("page", "0").param("size", "10").accept(MediaType.APPLICATION_JSON)).andDo(print()).andExpect(status().isOk()) | ||
.andExpect(jsonPath("$.pagedResources.content.[*].timestamp", contains("sometimestamp", "anothertimestamp", "lasttimestamp"))) | ||
.andExpect(jsonPath("$.pagedResources.content.[*].path", contains("foo.txt", "bar/foo.txt", "bar/baz.txt"))) | ||
.andExpect(jsonPath("$.pagedResources.content.[*].shortPath", contains("foo.txt", "bar/foo.txt", "bar/baz.txt"))) | ||
.andExpect(jsonPath("$.pagedResources.content.[*].local", contains(true, false, true))); | ||
} | ||
|
||
@Test | ||
public void testDelete() throws Exception { | ||
when(fileService.delete("pattern")).thenReturn(3); | ||
|
||
mockMvc.perform( | ||
delete("/batch/files").param("pattern", "pattern").accept(MediaType.APPLICATION_JSON)).andDo(print()).andExpect(status().isOk()) | ||
.andExpect(jsonPath("$.fileInfoResource.deleteCount", equalTo(3))); | ||
} | ||
} |