Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug 564420 move HC condition miner to new interfaces #259

Merged
merged 1 commit into from
Jun 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,20 @@
* Transport interface for {@link LicensingCondition}(s).
*
* @since 0.4.0
* @deprecated use {@code lic.internal.api.ConditionTransport}
*/
@Deprecated
public interface ConditionTransport {

/**
* Reads {@link LicensingCondition}(s) from the given {@link InputStream}.
* Reads {@link LicensingCondition}(s) from the given {@link InputStream}.
*
* @since 0.4.0
*/
Iterable<LicensingCondition> readConditions(InputStream input) throws IOException;

/**
* Writes {@link LicensingCondition}(s) from the given {@link OutputStream}.
* Writes {@link LicensingCondition}(s) from the given {@link OutputStream}.
*
* @since 0.4.0
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*******************************************************************************
* Copyright (c) 2020 ArSysOp
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* https://www.eclipse.org/legal/epl-2.0/.
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* ArSysOp - initial API and implementation
*******************************************************************************/
package org.eclipse.passage.lic.api.tests.conditions.mining;

import static org.junit.Assert.assertEquals;
import static org.junit.Assume.assumeTrue;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
import java.util.stream.Collectors;

import org.eclipse.passage.lic.internal.api.conditions.Condition;
import org.eclipse.passage.lic.internal.api.conditions.mining.ConditionTransport;
import org.junit.Test;

@SuppressWarnings("restriction")
public abstract class ConditionTransportContractTest {

@Test(expected = NullPointerException.class)
public void conditionsAreMandatory() throws IOException {
transport().write(null, new ByteArrayOutputStream());
}

@Test
public void readYourOwnWritings() throws IOException {
// given
Collection<Condition> sedentaries = conditions();
assumeTrue("Too few: supply at least two test conditions for transportation", sedentaries.size() > 1); //$NON-NLS-1$
ConditionTransport transport = transport();
// when
String serialized = write(transport, sedentaries);
Collection<Condition> nomads = read(transport, serialized);
// then
assertEquals(new HashSet<>(textual(sedentaries)), new HashSet<>(textual(nomads)));
}

private String write(ConditionTransport transport, Collection<Condition> conditions) throws IOException {
ByteArrayOutputStream output = new ByteArrayOutputStream();
transport.write(conditions, output);
return new String(output.toByteArray());
}

private Collection<Condition> read(ConditionTransport transport, String source) throws IOException {
return transport.read(new ByteArrayInputStream(source.getBytes()));
}

private Set<String> textual(Collection<Condition> conditions) {
return conditions.stream()//
.map(this::textual) //
.collect(Collectors.toSet());
}

/**
* Provide any textual representation of a condition that distinguishes two
* instances with differing content.
*/
protected abstract String textual(Condition condition);

/**
* Produce new instance of a transport under test
*/
protected abstract ConditionTransport transport();

/**
* Supply as least two test condition for transportation
*/
protected abstract Collection<Condition> conditions();
}