Skip to content

Commit

Permalink
Merge pull request #59 from ppi-ag/bug-order-loading
Browse files Browse the repository at this point in the history
Bug order loading
  • Loading branch information
JanSchankin committed Apr 6, 2021
2 parents 922511f + d7abc47 commit b77c47d
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package de.ppi.deepsampler.core.model;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;

Expand Down Expand Up @@ -54,6 +55,19 @@ public void add(final SampleDefinition sampleDefinition) {
samples.add(sampleDefinition);
}

/**
* <p>Removes the SampleDefinition at the given index.</p>
*
* <p>Its not possible to remove a given SampleDefinition by
* equality as a definition do not need to be unique plus the technical equality won't recognize all attributes
* of the sample.</p>
*
* @param index the index at which you want to remove the sample
*/
public void remove(int index) {
samples.remove(index);
}

/**
* Checks whether both methods are the same or not
*
Expand Down Expand Up @@ -124,7 +138,7 @@ public void setLastSampleDefinition(SampleDefinition sampleDefinition) {
}

public List<SampleDefinition> getSamples() {
return samples;
return Collections.unmodifiableList(samples);
}

public void clearCurrentParameterMatchers() {
Expand All @@ -144,7 +158,7 @@ public ParameterMatcher<?> getLastParameterMatcher() {
}

public List<ParameterMatcher<?>> getCurrentParameterMatchers() {
return currentParameterMatchers;
return Collections.unmodifiableList(currentParameterMatchers);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,14 @@ public void load() {
loadedSampledDefinitions.addAll(filteredMappedSample);
}

SampleRepository.getInstance().clear();
List<SampleDefinition> currentSampleDefinitions = SampleRepository.getInstance().getSamples();
for (int i = currentSampleDefinitions.size() - 1; i >= 0; --i) {
SampleDefinition definition = currentSampleDefinitions.get(i);
// we only remove definitions made for the persistence -> definitions without answers
if (definition.getAnswer() == null) {
SampleRepository.getInstance().remove(i);
}
}

for (final SampleDefinition sample : loadedSampledDefinitions) {
SampleRepository.getInstance().add(sample);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -847,4 +847,31 @@ void testComboMatcherSecondArgument() throws IOException {
Files.delete(Paths.get(pathToFile));
}

@Test
public void mixPureJavaApiAndPersistenceApi() throws IOException {
Sampler.clear();
final TestService testServiceSampler = Sampler.prepare(TestService.class);
Sample.of(testServiceSampler.testLocalDateTime());

getTestService().testLocalDateTime();

final String pathToFile = "./record/localDateTimeCanBeRecordedAndLoaded.json";
final PersistentSampleManager source = PersistentSampler.source(JsonSourceManager.builder().buildWithFile(pathToFile));
source.record();

assertFalse(SampleRepository.getInstance().isEmpty());
Sampler.clear();
assertTrue(SampleRepository.getInstance().isEmpty());

// MIX persistence definition and pure java definition
Sample.of(testServiceSampler.testLocalDateTime());
Sample.of(testServiceSampler.echoParameter("ABC")).is("CBD");
source.load();

assertFalse(SampleRepository.getInstance().isEmpty());
assertEquals(LocalDateTime.of(2020, 10, 29, 10, 10, 10), getTestService().testLocalDateTime());
assertEquals("CBD", getTestService().echoParameter("ABC"));
Files.delete(Paths.get(pathToFile));
}

}

0 comments on commit b77c47d

Please sign in to comment.