Refactor tests
This commit is contained in:
parent
7c8fb07b5d
commit
7bff8312b4
9 changed files with 96 additions and 22 deletions
|
@ -2,6 +2,8 @@ package eu.m724.jarupdater.object;
|
|||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class Version {
|
||||
/**
|
||||
* metadata file version
|
||||
|
@ -67,6 +69,16 @@ public class Version {
|
|||
public String getSha256() {
|
||||
return sha256;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (!(o instanceof Version)) return false;
|
||||
Version version = (Version) o;
|
||||
return id == version.id && timestamp == version.timestamp && Objects.equals(label, version.label) && Objects.equals(fileUrl, version.fileUrl) && Objects.equals(changelogUrl, version.changelogUrl) && Objects.equals(sha256, version.sha256);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(id, timestamp, label, fileUrl, changelogUrl, sha256);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@ public class SignatureVerifierImpl {
|
|||
* @return {@link RSAPublicKey} instance of the public key
|
||||
* @throws IOException if reading the key input stream failed
|
||||
*/
|
||||
static RSAPublicKey loadPublicKey(InputStream keyInputStream) throws IOException {
|
||||
public static RSAPublicKey loadPublicKey(InputStream keyInputStream) throws IOException {
|
||||
// Read the key file
|
||||
String keyContent = new String(keyInputStream.readAllBytes());
|
||||
|
||||
|
@ -57,7 +57,7 @@ public class SignatureVerifierImpl {
|
|||
* @param publicKeys the {@link RSAPublicKey}s
|
||||
* @throws VerificationException if verification failed
|
||||
*/
|
||||
static void verifyWithRsaKey(String jarPath, RSAPublicKey... publicKeys) throws VerificationException {
|
||||
public static void verifyWithRsaKey(String jarPath, RSAPublicKey... publicKeys) throws VerificationException {
|
||||
try {
|
||||
// Open the JAR file
|
||||
try (JarFile jarFile = new JarFile(jarPath, true)) {
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package jarupdater;
|
||||
package eu.m724.jarupdater.download;
|
||||
|
||||
import eu.m724.jarupdater.download.Downloader;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
|
@ -1,6 +1,4 @@
|
|||
package jarupdater;
|
||||
|
||||
import eu.m724.jarupdater.download.Downloader;
|
||||
package eu.m724.jarupdater.download;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
|
@ -1,11 +1,8 @@
|
|||
package jarupdater;
|
||||
|
||||
import java.nio.file.Path;
|
||||
package eu.m724.jarupdater.environment;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import eu.m724.jarupdater.environment.ConstantEnvironment;
|
||||
import eu.m724.jarupdater.environment.Environment;
|
||||
import java.nio.file.Path;
|
||||
|
||||
public class EnvironmentTest {
|
||||
@Test
|
|
@ -1,9 +1,7 @@
|
|||
package jarupdater;
|
||||
package eu.m724.jarupdater.live;
|
||||
|
||||
import eu.m724.jarupdater.environment.ConstantEnvironment;
|
||||
import eu.m724.jarupdater.environment.Environment;
|
||||
import eu.m724.jarupdater.live.MetadataDAO;
|
||||
import eu.m724.jarupdater.live.MetadataFacade;
|
||||
import eu.m724.jarupdater.object.Version;
|
||||
import org.junit.Test;
|
||||
|
|
@ -1,6 +1,5 @@
|
|||
package jarupdater;
|
||||
package eu.m724.jarupdater.live;
|
||||
|
||||
import eu.m724.jarupdater.live.MetadataDAO;
|
||||
import eu.m724.jarupdater.object.NoSuchVersionException;
|
||||
import eu.m724.jarupdater.object.Version;
|
||||
|
||||
|
@ -20,15 +19,15 @@ public class MockMetadataDAO implements MetadataDAO {
|
|||
@Override
|
||||
public CompletableFuture<Version> getMetadata(String channel, String versionLabel) {
|
||||
Version version = null;
|
||||
String fileUrl = "http://127.0.0.1:17357/" + channel + "/" + versionLabel + ".jar";
|
||||
String fileUrlPrefix = "http://127.0.0.1:17357/" + channel + "/";
|
||||
|
||||
switch (versionLabel) {
|
||||
case "1.0":
|
||||
version = new Version(1, 100, "1.0", fileUrl, null, "dd3822ed965b2820aa0800f04b86f26d0b656fca3b97ddd264046076f81e3a24");
|
||||
version = new Version(1, 100, "1.0", fileUrlPrefix + "1.0.jar", null, "dd3822ed965b2820aa0800f04b86f26d0b656fca3b97ddd264046076f81e3a24");
|
||||
break;
|
||||
case "1.1":
|
||||
case "latest":
|
||||
version = new Version(2, 200, "1.1", fileUrl, null,"4d59994f607b89987d5bff430a4229edbbb045b3da9eaf1c63fa8e5fb208d824");
|
||||
version = new Version(2, 200, "1.1", fileUrlPrefix + "1.1.jar", null,"4d59994f607b89987d5bff430a4229edbbb045b3da9eaf1c63fa8e5fb208d824");
|
||||
break;
|
||||
default:
|
||||
return CompletableFuture.failedFuture(new CompletionException(new NoSuchVersionException(channel, versionLabel)));
|
63
src/test/java/eu/m724/jarupdater/updater/UpdaterTest.java
Normal file
63
src/test/java/eu/m724/jarupdater/updater/UpdaterTest.java
Normal file
|
@ -0,0 +1,63 @@
|
|||
package eu.m724.jarupdater.updater;
|
||||
|
||||
import eu.m724.jarupdater.download.Downloader;
|
||||
import eu.m724.jarupdater.download.MockDownloader;
|
||||
import eu.m724.jarupdater.environment.ConstantEnvironment;
|
||||
import eu.m724.jarupdater.environment.Environment;
|
||||
import eu.m724.jarupdater.live.MetadataDAO;
|
||||
import eu.m724.jarupdater.live.MetadataFacade;
|
||||
import eu.m724.jarupdater.live.MockMetadataDAO;
|
||||
import eu.m724.jarupdater.object.Version;
|
||||
import eu.m724.jarupdater.verify.MockVerifier;
|
||||
import eu.m724.jarupdater.verify.Verifier;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class UpdaterTest {
|
||||
Updater updater;
|
||||
|
||||
private final Version expectedCurrentVersion = new Version(1, 100, "1.0", "http://127.0.0.1:17357/stable/1.0.jar", null, "dd3822ed965b2820aa0800f04b86f26d0b656fca3b97ddd264046076f81e3a24");
|
||||
private final Version expectedLatestVersion = new Version(2, 200, "1.1", "http://127.0.0.1:17357/stable/1.1.jar", null,"4d59994f607b89987d5bff430a4229edbbb045b3da9eaf1c63fa8e5fb208d824");
|
||||
|
||||
@Before
|
||||
public void createUpdater() {
|
||||
Environment environment = new ConstantEnvironment("1.0", "stable", Path.of("idontexist"));
|
||||
|
||||
MetadataDAO metadataDAO = new MockMetadataDAO();
|
||||
MetadataFacade metadataFacade = new MetadataFacade(environment, metadataDAO);
|
||||
|
||||
Downloader downloader = new MockDownloader();
|
||||
|
||||
Verifier verifier = new MockVerifier();
|
||||
|
||||
this.updater = new Updater(environment, metadataFacade, downloader, verifier);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testChannels() {
|
||||
List<String> channels = updater.getChannels().join();
|
||||
assertEquals(channels, Arrays.asList("stable", "beta", "alpha"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCurrentVersion() {
|
||||
Version currentVersion = updater.getCurrentVersion().join();
|
||||
|
||||
assertEquals(expectedCurrentVersion, currentVersion);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLatestVersion() {
|
||||
Version latestVersion = updater.getLatestVersion().join();
|
||||
|
||||
assertEquals(expectedLatestVersion, latestVersion);
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
package eu.m724.jarupdater.verify;
|
||||
|
||||
public class MockVerifier implements Verifier {
|
||||
@Override
|
||||
public void verify(String jarPath) throws VerificationException {
|
||||
return;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue