ConfigurationModel.java

1
/*-
2
 * #%L
3
 * io.earcam.utilitarian.site.search.offline
4
 * %%
5
 * Copyright (C) 2017 earcam
6
 * %%
7
 * SPDX-License-Identifier: (BSD-3-Clause OR EPL-1.0 OR Apache-2.0 OR MIT)
8
 *
9
 * You <b>must</b> choose to accept, in full - any individual or combination of
10
 * the following licenses:
11
 * <ul>
12
 * 	<li><a href="https://opensource.org/licenses/BSD-3-Clause">BSD-3-Clause</a></li>
13
 * 	<li><a href="https://www.eclipse.org/legal/epl-v10.html">EPL-1.0</a></li>
14
 * 	<li><a href="https://www.apache.org/licenses/LICENSE-2.0">Apache-2.0</a></li>
15
 * 	<li><a href="https://opensource.org/licenses/MIT">MIT</a></li>
16
 * </ul>
17
 * #L%
18
 */
19
package io.earcam.utilitarian.site.search.offline;
20
21
import static io.earcam.utilitarian.site.search.offline.Crawler.crawler;
22
import static java.util.stream.Collectors.toMap;
23
import static java.util.stream.Collectors.toSet;
24
import static java.util.stream.StreamSupport.stream;
25
26
import java.io.File;
27
import java.net.URI;
28
import java.nio.file.Path;
29
import java.util.List;
30
import java.util.Map;
31
import java.util.ServiceLoader;
32
import java.util.Set;
33
import java.util.stream.Stream;
34
35
public abstract class ConfigurationModel {
36
37
	public static class Step extends ConfigurationModel {}
38
39
	public static class Mapping {
40
41
		private File dir;
42
		private URI uri;
43
44
45
		public File getDir()
46
		{
47 1 1. getDir : mutated return of Object value for io/earcam/utilitarian/site/search/offline/ConfigurationModel$Mapping::getDir to ( if (x != null) null else throw new RuntimeException ) → KILLED
			return dir;
48
		}
49
50
51
		static Path dirAsPath(Mapping mapping)
52
		{
53 1 1. dirAsPath : mutated return of Object value for io/earcam/utilitarian/site/search/offline/ConfigurationModel$Mapping::dirAsPath to ( if (x != null) null else throw new RuntimeException ) → KILLED
			return mapping.getDir().toPath();
54
		}
55
56
57
		public void setDir(File dir)
58
		{
59
			this.dir = dir;
60
		}
61
62
63
		public URI getUri()
64
		{
65 1 1. getUri : mutated return of Object value for io/earcam/utilitarian/site/search/offline/ConfigurationModel$Mapping::getUri to ( if (x != null) null else throw new RuntimeException ) → KILLED
			return uri;
66
		}
67
68
69
		public void setUri(URI uri)
70
		{
71
			this.uri = uri;
72
		}
73
	}
74
75
	public static class Indexing extends ConfigurationModel {
76
77
		public Indexer build()
78
		{
79 1 1. build : mutated return of Object value for io/earcam/utilitarian/site/search/offline/ConfigurationModel$Indexing::build to ( if (x != null) null else throw new RuntimeException ) → KILLED
			return create(Indexer.class, this);
80
		}
81
	}
82
83
84
	static <T extends Component> T create(Class<T> type, ConfigurationModel model)
85
	{
86
		T component = serviceById(type, model.getId());
87 1 1. create : removed call to io/earcam/utilitarian/site/search/offline/Component::configure → KILLED
		component.configure(model.getConfiguration());
88 1 1. create : mutated return of Object value for io/earcam/utilitarian/site/search/offline/ConfigurationModel::create to ( if (x != null) null else throw new RuntimeException ) → KILLED
		return component;
89
	}
90
91
92
	private static <S extends Component> S serviceById(Class<S> service, String id)
93
	{
94 1 1. serviceById : mutated return of Object value for io/earcam/utilitarian/site/search/offline/ConfigurationModel::serviceById to ( if (x != null) null else throw new RuntimeException ) → KILLED
		return serviceStream(service)
95 1 1. lambda$serviceById$0 : replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED
				.filter(s -> id.equals(s.id()))
96
				.findFirst()
97 1 1. lambda$serviceById$1 : mutated return of Object value for io/earcam/utilitarian/site/search/offline/ConfigurationModel::lambda$serviceById$1 to ( if (x != null) null else throw new RuntimeException ) → SURVIVED
				.orElseThrow(() -> new IllegalStateException("Not SPI service with id '" + id
98
						+ "' found of type '" + service.getCanonicalName() + "'"));
99
	}
100
101
102
	private static <S extends Component> Stream<S> serviceStream(Class<S> service)
103
	{
104 1 1. serviceStream : mutated return of Object value for io/earcam/utilitarian/site/search/offline/ConfigurationModel::serviceStream to ( if (x != null) null else throw new RuntimeException ) → KILLED
		return stream(ServiceLoader.load(service).spliterator(), false);
105
	}
106
107
	public static class Crawling {
108
109
		private List<Mapping> mappings;
110
111
		private List<Step> steps;
112
113
114
		public List<Mapping> getMappings()
115
		{
116 1 1. getMappings : mutated return of Object value for io/earcam/utilitarian/site/search/offline/ConfigurationModel$Crawling::getMappings to ( if (x != null) null else throw new RuntimeException ) → KILLED
			return mappings;
117
		}
118
119
120
		public void setMappings(List<Mapping> mappings)
121
		{
122
			this.mappings = mappings;
123
		}
124
125
126
		public List<Step> getSteps()
127
		{
128 1 1. getSteps : mutated return of Object value for io/earcam/utilitarian/site/search/offline/ConfigurationModel$Crawling::getSteps to ( if (x != null) null else throw new RuntimeException ) → KILLED
			return steps;
129
		}
130
131
132
		public void setSteps(List<Step> steps)
133
		{
134
			this.steps = steps;
135
		}
136
137
138
		public Crawler build()
139
		{
140
			Crawler crawler = crawler(mappings.stream()
141
					.collect(toMap(Mapping::dirAsPath, Mapping::getUri)));
142
143
			Set<String> filters = serviceIds(Filter.class);
144
			Set<String> processors = serviceIds(Processor.class);
145
146
			for(Step step : steps) {
147 1 1. build : negated conditional → KILLED
				if(filters.contains(step.getId())) {
148
					crawler.filter(create(Filter.class, step));
149
150 1 1. build : negated conditional → KILLED
				} else if(processors.contains(step.getId())) {
151
					crawler.processor(create(Processor.class, step));
152
153
				} else {
154
					throw new IllegalStateException("No filter or processor found via SPI with ID '" + step.getId() + "'");
155
				}
156
			}
157 1 1. build : mutated return of Object value for io/earcam/utilitarian/site/search/offline/ConfigurationModel$Crawling::build to ( if (x != null) null else throw new RuntimeException ) → KILLED
			return crawler;
158
		}
159
160
161
		private static <S extends Component> Set<String> serviceIds(Class<S> service)
162
		{
163 1 1. serviceIds : mutated return of Object value for io/earcam/utilitarian/site/search/offline/ConfigurationModel$Crawling::serviceIds to ( if (x != null) null else throw new RuntimeException ) → KILLED
			return serviceStream(service)
164
					.map(Component::id)
165
					.collect(toSet());
166
		}
167
	}
168
169
	private String id;
170
171
	private Map<String, String> configuration;
172
173
174
	public String getId()
175
	{
176 1 1. getId : mutated return of Object value for io/earcam/utilitarian/site/search/offline/ConfigurationModel::getId to ( if (x != null) null else throw new RuntimeException ) → KILLED
		return id;
177
	}
178
179
180
	public void setId(String id)
181
	{
182
		this.id = id;
183
	}
184
185
186
	public Map<String, String> getConfiguration()
187
	{
188 1 1. getConfiguration : mutated return of Object value for io/earcam/utilitarian/site/search/offline/ConfigurationModel::getConfiguration to ( if (x != null) null else throw new RuntimeException ) → KILLED
		return configuration;
189
	}
190
191
192
	public void setConfiguration(Map<String, String> configuration)
193
	{
194
		this.configuration = configuration;
195
	}
196
}

Mutations

47

1.1
Location : getDir
Killed by : io.earcam.utilitarian.site.search.offline.ConfigurationModelTest.mappingsToExpectedJson()
mutated return of Object value for io/earcam/utilitarian/site/search/offline/ConfigurationModel$Mapping::getDir to ( if (x != null) null else throw new RuntimeException ) → KILLED

53

1.1
Location : dirAsPath
Killed by : io.earcam.utilitarian.site.search.offline.SearchTest.equivalence()
mutated return of Object value for io/earcam/utilitarian/site/search/offline/ConfigurationModel$Mapping::dirAsPath to ( if (x != null) null else throw new RuntimeException ) → KILLED

65

1.1
Location : getUri
Killed by : io.earcam.utilitarian.site.search.offline.ConfigurationModelTest.mappingsToExpectedJson()
mutated return of Object value for io/earcam/utilitarian/site/search/offline/ConfigurationModel$Mapping::getUri to ( if (x != null) null else throw new RuntimeException ) → KILLED

79

1.1
Location : build
Killed by : io.earcam.utilitarian.site.search.offline.SearchTest.equivalence()
mutated return of Object value for io/earcam/utilitarian/site/search/offline/ConfigurationModel$Indexing::build to ( if (x != null) null else throw new RuntimeException ) → KILLED

87

1.1
Location : create
Killed by : io.earcam.utilitarian.site.search.offline.SearchTest.equivalence()
removed call to io/earcam/utilitarian/site/search/offline/Component::configure → KILLED

88

1.1
Location : create
Killed by : io.earcam.utilitarian.site.search.offline.SearchTest.equivalence()
mutated return of Object value for io/earcam/utilitarian/site/search/offline/ConfigurationModel::create to ( if (x != null) null else throw new RuntimeException ) → KILLED

94

1.1
Location : serviceById
Killed by : io.earcam.utilitarian.site.search.offline.SearchTest.equivalence()
mutated return of Object value for io/earcam/utilitarian/site/search/offline/ConfigurationModel::serviceById to ( if (x != null) null else throw new RuntimeException ) → KILLED

95

1.1
Location : lambda$serviceById$0
Killed by : io.earcam.utilitarian.site.search.offline.SearchTest.equivalence()
replaced return of integer sized value with (x == 0 ? 1 : 0) → KILLED

97

1.1
Location : lambda$serviceById$1
Killed by : none
mutated return of Object value for io/earcam/utilitarian/site/search/offline/ConfigurationModel::lambda$serviceById$1 to ( if (x != null) null else throw new RuntimeException ) → SURVIVED

104

1.1
Location : serviceStream
Killed by : io.earcam.utilitarian.site.search.offline.SearchTest.equivalence()
mutated return of Object value for io/earcam/utilitarian/site/search/offline/ConfigurationModel::serviceStream to ( if (x != null) null else throw new RuntimeException ) → KILLED

116

1.1
Location : getMappings
Killed by : io.earcam.utilitarian.site.search.offline.ConfigurationModelTest.mappingsToExpectedJson()
mutated return of Object value for io/earcam/utilitarian/site/search/offline/ConfigurationModel$Crawling::getMappings to ( if (x != null) null else throw new RuntimeException ) → KILLED

128

1.1
Location : getSteps
Killed by : io.earcam.utilitarian.site.search.offline.ConfigurationModelTest.mappingsToExpectedJson()
mutated return of Object value for io/earcam/utilitarian/site/search/offline/ConfigurationModel$Crawling::getSteps to ( if (x != null) null else throw new RuntimeException ) → KILLED

147

1.1
Location : build
Killed by : io.earcam.utilitarian.site.search.offline.SearchTest.equivalence()
negated conditional → KILLED

150

1.1
Location : build
Killed by : io.earcam.utilitarian.site.search.offline.SearchTest.equivalence()
negated conditional → KILLED

157

1.1
Location : build
Killed by : io.earcam.utilitarian.site.search.offline.SearchTest.equivalence()
mutated return of Object value for io/earcam/utilitarian/site/search/offline/ConfigurationModel$Crawling::build to ( if (x != null) null else throw new RuntimeException ) → KILLED

163

1.1
Location : serviceIds
Killed by : io.earcam.utilitarian.site.search.offline.SearchTest.equivalence()
mutated return of Object value for io/earcam/utilitarian/site/search/offline/ConfigurationModel$Crawling::serviceIds to ( if (x != null) null else throw new RuntimeException ) → KILLED

176

1.1
Location : getId
Killed by : io.earcam.utilitarian.site.search.offline.SearchTest.equivalence()
mutated return of Object value for io/earcam/utilitarian/site/search/offline/ConfigurationModel::getId to ( if (x != null) null else throw new RuntimeException ) → KILLED

188

1.1
Location : getConfiguration
Killed by : io.earcam.utilitarian.site.search.offline.SearchTest.equivalence()
mutated return of Object value for io/earcam/utilitarian/site/search/offline/ConfigurationModel::getConfiguration to ( if (x != null) null else throw new RuntimeException ) → KILLED

Active mutators

Tests examined


Report generated by PIT 1.4.3