-
Notifications
You must be signed in to change notification settings - Fork 8
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 #80 from eparovyshnaya/558321-tests
558321 design general purpose interfaces to empower reporting - test ref implementation is provided to illustrate efforts on implementing export to several output formats - `ExportTest` is going to be exhaustively documented later in a separate commit together with the api package Signed-off-by: elena.parovyshnaya <[email protected]>
- Loading branch information
Showing
14 changed files
with
547 additions
and
0 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
11 changes: 11 additions & 0 deletions
11
tests/org.eclipse.passage.loc.yars.api.tests/META-INF/MANIFEST.MF
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,11 @@ | ||
Manifest-Version: 1.0 | ||
Automatic-Module-Name: org.eclipse.passage.loc.yars.api.tests | ||
Bundle-ManifestVersion: 2 | ||
Bundle-SymbolicName: org.eclipse.passage.loc.yars.api.tests | ||
Bundle-Version: 0.1.0.qualifier | ||
Bundle-Name: %Bundle-Name | ||
Bundle-Vendor: %Bundle-Vendor | ||
Bundle-Copyright: %Bundle-Copyright | ||
Bundle-RequiredExecutionEnvironment: JavaSE-1.8 | ||
Require-Bundle: org.junit;bundle-version="4.12.0", | ||
org.eclipse.passage.loc.yars.api;bundle-version="0.1.0" |
23 changes: 23 additions & 0 deletions
23
tests/org.eclipse.passage.loc.yars.api.tests/OSGI-INF/l10n/bundle.properties
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,23 @@ | ||
#Properties file for org.eclipse.passage.loc.yars.api.tests | ||
############################################################################### | ||
# Copyright (c) 2019 ArSysOp and others | ||
# | ||
# This program and the accompanying materials are made available under the | ||
# terms of the Eclipse Public License 2.0 which is available at | ||
# http://www.eclipse.org/legal/epl-2.0. | ||
# | ||
# SPDX-License-Identifier: EPL-2.0 | ||
# | ||
# Contributors: | ||
# ArSysOp - initial API and implementation | ||
############################################################################### | ||
|
||
Bundle-Name = Passage LOC YARS API Tests | ||
Bundle-Vendor = Eclipse Passage | ||
Bundle-Copyright = Copyright (c) 2019 ArSysOp and others.\n\ | ||
\n\ | ||
This program and the accompanying materials are made\n\ | ||
available under the terms of the Eclipse Public License 2.0\n\ | ||
which is available at https://www.eclipse.org/legal/epl-2.0/\n\ | ||
\n\ | ||
SPDX-License-Identifier: EPL-2.0\n\ |
18 changes: 18 additions & 0 deletions
18
tests/org.eclipse.passage.loc.yars.api.tests/build.properties
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,18 @@ | ||
############################################################################### | ||
# Copyright (c) 2019 ArSysOp and others | ||
# | ||
# This program and the accompanying materials are made available under the | ||
# terms of the Eclipse Public License 2.0 which is available at | ||
# http://www.eclipse.org/legal/epl-2.0. | ||
# | ||
# SPDX-License-Identifier: EPL-2.0 | ||
# | ||
# Contributors: | ||
# ArSysOp - initial API and implementation | ||
############################################################################### | ||
|
||
source.. = src/ | ||
output.. = target/classes/ | ||
bin.includes = META-INF/,\ | ||
.,\ | ||
OSGI-INF/ |
38 changes: 38 additions & 0 deletions
38
....passage.loc.yars.api.tests/src/org/eclipse/passage/loc/yars/internal/api/export/All.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,38 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2019 ArSysOp | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* ArSysOp - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.passage.loc.yars.internal.api.export; | ||
|
||
import org.eclipse.passage.loc.yars.internal.api.FetchParams; | ||
import org.eclipse.passage.loc.yars.internal.api.FetchedData; | ||
import org.eclipse.passage.loc.yars.internal.api.Query; | ||
import org.eclipse.passage.loc.yars.internal.api.model.InMemoryStorage; | ||
|
||
@SuppressWarnings("restriction") | ||
public class All implements Query<InMemoryStorage, ExportedEntry, FetchParams> { | ||
|
||
@Override | ||
public String id() { | ||
return "ALL"; //$NON-NLS-1$ | ||
} | ||
|
||
@Override | ||
public String description() { | ||
return "Fetch all entries from an im-memory storage in one fell swoop"; //$NON-NLS-1$ | ||
} | ||
|
||
@Override | ||
public FetchedData<InMemoryStorage, ExportedEntry> data(InMemoryStorage base, FetchParams params) { | ||
return new Fetch(base); | ||
} | ||
|
||
} |
59 changes: 59 additions & 0 deletions
59
....passage.loc.yars.api.tests/src/org/eclipse/passage/loc/yars/internal/api/export/Csv.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,59 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2019 ArSysOp | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* ArSysOp - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.passage.loc.yars.internal.api.export; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
import org.eclipse.passage.loc.yars.internal.api.ListMedia; | ||
|
||
@SuppressWarnings("restriction") | ||
class Csv implements ListMedia<ExportedEntry, String> { | ||
|
||
private final StringBuilder builder; | ||
private final List<String> header; | ||
|
||
private Csv(StringBuilder builder, List<String> header) { | ||
this.builder = builder; | ||
this.header = header; | ||
} | ||
|
||
Csv(String... header) { | ||
this(new StringBuilder(), Arrays.asList(header)); | ||
} | ||
|
||
@Override | ||
public Csv start() { | ||
builder.delete(0, builder.length()); | ||
header.forEach(facet -> builder.append(facet).append(";")); //$NON-NLS-1$ | ||
return this; | ||
} | ||
|
||
@Override | ||
public Csv startNode(ExportedEntry node) { | ||
builder.append("\n"); //$NON-NLS-1$ | ||
return this; | ||
} | ||
|
||
@Override | ||
public Csv inner(String data, String name) { | ||
builder.append(data).append(";"); //$NON-NLS-1$ | ||
return this; | ||
} | ||
|
||
@Override | ||
public String content() { | ||
return builder.toString(); | ||
} | ||
|
||
} |
42 changes: 42 additions & 0 deletions
42
...e.loc.yars.api.tests/src/org/eclipse/passage/loc/yars/internal/api/export/Enlistment.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,42 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2019 ArSysOp | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* ArSysOp - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.passage.loc.yars.internal.api.export; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import org.eclipse.passage.loc.yars.internal.api.ListMedia; | ||
|
||
@SuppressWarnings("restriction") | ||
public class Enlistment<T> implements ListMedia<T, List<T>> { | ||
|
||
private final List<T> content = new ArrayList<>(); | ||
|
||
@Override | ||
public Enlistment<T> start() { | ||
content.clear(); | ||
return this; | ||
} | ||
|
||
@Override | ||
public Enlistment<T> startNode(T root) { | ||
content.add(root); | ||
return this; | ||
} | ||
|
||
@Override | ||
public List<T> content() { | ||
return content; | ||
} | ||
|
||
} |
36 changes: 36 additions & 0 deletions
36
...ssage.loc.yars.api.tests/src/org/eclipse/passage/loc/yars/internal/api/export/Export.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,36 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2019 ArSysOp | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* ArSysOp - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.passage.loc.yars.internal.api.export; | ||
|
||
import org.eclipse.passage.loc.yars.internal.api.ExportData; | ||
import org.eclipse.passage.loc.yars.internal.api.FetchedData; | ||
import org.eclipse.passage.loc.yars.internal.api.ListMedia; | ||
import org.eclipse.passage.loc.yars.internal.api.model.InMemoryStorage; | ||
|
||
@SuppressWarnings("restriction") | ||
class Export implements ExportData<ExportedEntry> { | ||
|
||
private final FetchedData<InMemoryStorage, ExportedEntry> query; | ||
|
||
Export(FetchedData<InMemoryStorage, ExportedEntry> query) { | ||
this.query = query; | ||
} | ||
|
||
@Override | ||
public <C> void write(ListMedia<ExportedEntry, C> media) { | ||
media.start(); | ||
query.get().forEach(d -> d.write(media)); | ||
media.finish(); | ||
} | ||
|
||
} |
99 changes: 99 additions & 0 deletions
99
...e.loc.yars.api.tests/src/org/eclipse/passage/loc/yars/internal/api/export/ExportTest.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,99 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2019 ArSysOp | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* ArSysOp - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.passage.loc.yars.internal.api.export; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
import java.util.Arrays; | ||
|
||
import org.eclipse.passage.loc.yars.internal.api.FetchParams; | ||
import org.eclipse.passage.loc.yars.internal.api.ListMedia; | ||
import org.eclipse.passage.loc.yars.internal.api.Storage; | ||
import org.eclipse.passage.loc.yars.internal.api.model.InMemoryStorage; | ||
import org.eclipse.passage.loc.yars.internal.api.model.StoredEntry; | ||
import org.junit.Test; | ||
|
||
/** | ||
* <p> | ||
* Let's say, you have a domain class {@linkplain StoredEntry} and a | ||
* {@linkplain Storage} - some coverer, that can somehow provide access to all | ||
* existing instances. | ||
* </p> | ||
* <p> | ||
* You desire to | ||
* </p> | ||
* <ul> | ||
* <li>have a look at all entries</li> | ||
* <li>get some information from each</li> | ||
* <li>and {@code write} this information to some output format.</li> | ||
* </ul> | ||
* | ||
* <p> | ||
* Here what you should do to make this happen | ||
* </p> | ||
* <ul> | ||
* <li>implement a {@linkplain Query}</li> | ||
* <li>Form a new class to keep information of interest(here it is called | ||
* {@linkplain ExportedEntry}</li> | ||
* <li></li> | ||
* <li></li> | ||
* </ul> | ||
* | ||
*/ | ||
@SuppressWarnings("restriction") | ||
public class ExportTest { | ||
|
||
@Test | ||
public void testCsv() { | ||
assertEquals("name;\nGammy;\nQuami;\nTsunami;", //$NON-NLS-1$ | ||
queryResult(new Csv("name"))); //$NON-NLS-1$ | ||
} | ||
|
||
@Test | ||
public void testEnlistment() { | ||
assertEquals(Arrays.asList( // | ||
new ExportedEntry("Gammy"), //$NON-NLS-1$ | ||
new ExportedEntry("Quami"), //$NON-NLS-1$ | ||
new ExportedEntry("Tsunami")), //$NON-NLS-1$ | ||
queryResult(new Enlistment<>())); | ||
} | ||
|
||
@Test | ||
public void testJson() { | ||
assertEquals("{\n" + //$NON-NLS-1$ | ||
"\t\"node\" : {\n" + //$NON-NLS-1$ | ||
"\t\t\"name\" : \"Gammy\"\n" + //$NON-NLS-1$ | ||
"\t}\n" + //$NON-NLS-1$ | ||
"\t\"node\" : {\n" + //$NON-NLS-1$ | ||
"\t\t\"name\" : \"Quami\"\n" + //$NON-NLS-1$ | ||
"\t}\n" + //$NON-NLS-1$ | ||
"\t\"node\" : {\n" + //$NON-NLS-1$ | ||
"\t\t\"name\" : \"Tsunami\"\n" + //$NON-NLS-1$ | ||
"\t}\n" + //$NON-NLS-1$ | ||
"}\n", //$NON-NLS-1$ | ||
queryResult(new Json())); | ||
} | ||
|
||
private <T> T queryResult(ListMedia<ExportedEntry, T> media) { | ||
new Export(new All().data(// | ||
new InMemoryStorage( // | ||
new StoredEntry("Gammy", "US"), //$NON-NLS-1$ //$NON-NLS-2$ | ||
new StoredEntry("Quami", "France"), //$NON-NLS-1$ //$NON-NLS-2$ | ||
new StoredEntry("Tsunami", "Japan")//$NON-NLS-1$ //$NON-NLS-2$ | ||
), // | ||
new FetchParams.Empty()))// | ||
.write(media); | ||
return media.content(); | ||
} | ||
|
||
} |
49 changes: 49 additions & 0 deletions
49
...oc.yars.api.tests/src/org/eclipse/passage/loc/yars/internal/api/export/ExportedEntry.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,49 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2019 ArSysOp | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* ArSysOp - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.passage.loc.yars.internal.api.export; | ||
|
||
import java.util.Objects; | ||
|
||
import org.eclipse.passage.loc.yars.internal.api.ListMedia; | ||
|
||
@SuppressWarnings("restriction") | ||
public class ExportedEntry { | ||
|
||
private String name; | ||
|
||
public ExportedEntry(String name) { | ||
this.name = name; | ||
} | ||
|
||
public <T> void write(ListMedia<ExportedEntry, T> media) { | ||
media.startNode(this)// | ||
.inner(name, "name") //$NON-NLS-1$ | ||
.finishNode(this); | ||
} | ||
|
||
@Override // generated | ||
public boolean equals(Object o) { | ||
if (this == o) | ||
return true; | ||
if (o == null || getClass() != o.getClass()) | ||
return false; | ||
ExportedEntry exportedEntry = (ExportedEntry) o; | ||
return Objects.equals(name, exportedEntry.name); | ||
} | ||
|
||
@Override // generated | ||
public int hashCode() { | ||
return name != null ? name.hashCode() : 0; | ||
} | ||
|
||
} |
Oops, something went wrong.