How to use Versioning class of org.testcontainers.utility package

Best Testcontainers-java code snippet using org.testcontainers.utility.Versioning

Source:DockerImageName.java Github

copy

Full Screen

...6import lombok.Getter;7import lombok.With;8import org.jetbrains.annotations.NotNull;9import org.jetbrains.annotations.Nullable;10import org.testcontainers.utility.Versioning.Sha256Versioning;11import org.testcontainers.utility.Versioning.TagVersioning;12import java.util.regex.Pattern;13@EqualsAndHashCode(exclude = { "rawName", "compatibleSubstituteFor" })14@AllArgsConstructor(access = AccessLevel.PRIVATE)15public final class DockerImageName {16 /* Regex patterns used for validation */17 private static final String ALPHA_NUMERIC = "[a-z0-9]+";18 private static final String SEPARATOR = "([.]|_{1,2}|-+)";19 private static final String REPO_NAME_PART = ALPHA_NUMERIC + "(" + SEPARATOR + ALPHA_NUMERIC + ")*";20 private static final Pattern REPO_NAME = Pattern.compile(REPO_NAME_PART + "(/" + REPO_NAME_PART + ")*");21 private final String rawName;22 @With @Getter private final String registry;23 @With @Getter private final String repository;24 @NotNull @With(AccessLevel.PRIVATE)25 private final Versioning versioning;26 @Nullable @With(AccessLevel.PRIVATE)27 private final DockerImageName compatibleSubstituteFor;28 /**29 * Parses a docker image name from a provided string.30 *31 * @param fullImageName in standard Docker format, e.g. <code>name:tag</code>,32 * <code>some.registry/path/name:tag</code>,33 * <code>some.registry/path/name@sha256:abcdef...</code>, etc.34 */35 public static DockerImageName parse(String fullImageName) {36 return new DockerImageName(fullImageName);37 }38 /**39 * Parses a docker image name from a provided string.40 *41 * @param fullImageName in standard Docker format, e.g. <code>name:tag</code>,42 * <code>some.registry/path/name:tag</code>,43 * <code>some.registry/path/name@sha256:abcdef...</code>, etc.44 * @deprecated use {@link DockerImageName#parse(String)} instead45 */46 @Deprecated47 public DockerImageName(String fullImageName) {48 this.rawName = fullImageName;49 final int slashIndex = fullImageName.indexOf('/');50 String remoteName;51 if (slashIndex == -1 ||52 (!fullImageName.substring(0, slashIndex).contains(".") &&53 !fullImageName.substring(0, slashIndex).contains(":") &&54 !fullImageName.substring(0, slashIndex).equals("localhost"))) {55 registry = "";56 remoteName = fullImageName;57 } else {58 registry = fullImageName.substring(0, slashIndex);59 remoteName = fullImageName.substring(slashIndex + 1);60 }61 if (remoteName.contains("@sha256:")) {62 repository = remoteName.split("@sha256:")[0];63 versioning = new Sha256Versioning(remoteName.split("@sha256:")[1]);64 } else if (remoteName.contains(":")) {65 repository = remoteName.split(":")[0];66 versioning = new TagVersioning(remoteName.split(":")[1]);67 } else {68 repository = remoteName;69 versioning = Versioning.ANY;70 }71 compatibleSubstituteFor = null;72 }73 /**74 * Parses a docker image name from a provided string, and uses a separate provided version.75 *76 * @param nameWithoutTag in standard Docker format, e.g. <code>name</code>,77 * <code>some.registry/path/name</code>,78 * <code>some.registry/path/name</code>, etc.79 * @param version a docker image version identifier, either as a tag or sha256 checksum, e.g.80 * <code>tag</code>,81 * <code>sha256:abcdef...</code>.82 * @deprecated use {@link DockerImageName#parse(String)}.{@link DockerImageName#withTag(String)} instead83 */84 @Deprecated85 public DockerImageName(String nameWithoutTag, @NotNull String version) {86 this.rawName = nameWithoutTag;87 final int slashIndex = nameWithoutTag.indexOf('/');88 String remoteName;89 if (slashIndex == -1 ||90 (!nameWithoutTag.substring(0, slashIndex).contains(".") &&91 !nameWithoutTag.substring(0, slashIndex).contains(":") &&92 !nameWithoutTag.substring(0, slashIndex).equals("localhost"))) {93 registry = "";94 remoteName = nameWithoutTag;95 } else {96 registry = nameWithoutTag.substring(0, slashIndex);97 remoteName = nameWithoutTag.substring(slashIndex + 1);98 }99 if (version.startsWith("sha256:")) {100 repository = remoteName;101 versioning = new Sha256Versioning(version.replace("sha256:", ""));102 } else {103 repository = remoteName;104 versioning = new TagVersioning(version);105 }106 compatibleSubstituteFor = null;107 }108 /**109 * @return the unversioned (non 'tag') part of this name110 */111 public String getUnversionedPart() {112 if (!"".equals(registry)) {113 return registry + "/" + repository;114 } else {115 return repository;116 }117 }118 /**119 * @return the versioned part of this name (tag or sha256)120 */121 public String getVersionPart() {122 return versioning.toString();123 }124 /**125 * @return canonical name for the image126 */127 public String asCanonicalNameString() {128 return getUnversionedPart() + versioning.getSeparator() + getVersionPart();129 }130 @Override131 public String toString() {132 return asCanonicalNameString();133 }134 /**135 * Is the image name valid?136 *137 * @throws IllegalArgumentException if not valid138 */139 public void assertValid() {140 //noinspection UnstableApiUsage141 HostAndPort.fromString(registry); // return value ignored - this throws if registry is not a valid host:port string142 if (!REPO_NAME.matcher(repository).matches()) {143 throw new IllegalArgumentException(repository + " is not a valid Docker image name (in " + rawName + ")");144 }145 if (!versioning.isValid()) {146 throw new IllegalArgumentException(versioning + " is not a valid image versioning identifier (in " + rawName + ")");147 }148 }149 /**150 * @param newTag version tag for the copy to use151 * @return an immutable copy of this {@link DockerImageName} with the new version tag152 */153 public DockerImageName withTag(final String newTag) {154 return withVersioning(new TagVersioning(newTag));155 }156 /**157 * Declare that this {@link DockerImageName} is a compatible substitute for another image - i.e. that this image158 * behaves as the other does, and is compatible with Testcontainers' assumptions about the other image.159 *160 * @param otherImageName the image name of the other image161 * @return an immutable copy of this {@link DockerImageName} with the compatibility declaration attached.162 */163 public DockerImageName asCompatibleSubstituteFor(String otherImageName) {164 return withCompatibleSubstituteFor(DockerImageName.parse(otherImageName));165 }166 /**167 * Declare that this {@link DockerImageName} is a compatible substitute for another image - i.e. that this image168 * behaves as the other does, and is compatible with Testcontainers' assumptions about the other image....

Full Screen

Full Screen

Source:KafkaJsonVersioningTest.java Github

copy

Full Screen

...23import static org.mockito.Mockito.verify;24@SpringBootTest25@Testcontainers26@ActiveProfiles("kafka-json-versioning")27class KafkaJsonVersioningTest {28 @Container29 private static final KafkaContainer kafkaContainer = new KafkaContainer(DockerImageName.parse("confluentinc/cp-kafka:5.4.3"));30 @Autowired31 private JsonVersioningProducer producer;32 @SpyBean33 private JsonVersioningConsumer consumer;34 @Value("${test.topic:test-topic}")35 private String topic;36 @Captor37 private ArgumentCaptor<ConsumerRecord<String, TestObject>> argumentCaptor;38 @DynamicPropertySource39 static void kafkaProperties(DynamicPropertyRegistry registry) {40 registry.add("spring.kafka.bootstrap-servers", kafkaContainer::getBootstrapServers);41 }42 @Test43 void testV1() {44 TestObjectV1 testObj = TestObjectV1.builder().value1("Test value 1").value2(99).build();45 producer.send(topic, testObj);46 // Verify the consumer's KafkaListener was called at all47 await().atMost(5, SECONDS).untilAsserted(() ->verify(consumer).listen(argumentCaptor.capture()));...

Full Screen

Full Screen

Versioning

Using AI Code Generation

copy

Full Screen

1import org.testcontainers.utility.Versioning;2public class VersioningDemo {3 public static void main(String[] args) {4 String version = Versioning.getVersion();5 System.out.println("Version: " + version);6 }7}

Full Screen

Full Screen

Versioning

Using AI Code Generation

copy

Full Screen

1package org.testcontainers.utility;2import org.junit.Test;3import org.testcontainers.utility.Versioning;4public class VersioningTest {5 public void getVersionTest() {6 String version = Versioning.getVersion();7 System.out.println("version of testcontainers is: " +

Full Screen

Full Screen

Versioning

Using AI Code Generation

copy

Full Screen

1import org.testcontainers.containers.MySQLContainer;2import org.testcontainers.utility.Versioning;3public class 1 {4 public static void main(String[] args) {5 String version = Versioning.getVersion();6 System.out.println(version);7 }8}

Full Screen

Full Screen

Versioning

Using AI Code Generation

copy

Full Screen

1import java.io.IOException;2import org.testcontainers.utility.Versioning;3public class VersioningClass {4 public static void main(String[] args) throws IOException {5 String version = Versioning.getVersion();6 System.out.println(version);7 }8}

Full Screen

Full Screen

Versioning

Using AI Code Generation

copy

Full Screen

1import org.testcontainers.utility.Versioning;2public class VersioningDemo {3 public static void main(String[] args) {4 System.out.println("Versioning class demo");5 String version = Versioning.getVersion();6 System.out.println("version = " + version);7 }8}9import org.testcontainers.containers.Version;10public class VersionDemo {11 public static void main(String[] args) {12 System.out.println("Version class demo");13 String version = Version.getVersion();14 System.out.println("version = " + version);15 }16}17import org.testcontainers.utility.DockerImageName;18public class DockerImageNameDemo {19 public static void main(String[] args) {20 System.out.println("DockerImageName class demo");21 DockerImageName name = DockerImageName.parse("ubuntu");22 System.out.println("name = " + name);23 }24}25import org.testcontainers.containers.GenericContainer;26public class GenericContainerDemo {27 public static void main(String[] args) {28 System.out.println("GenericContainer class demo");29 try (GenericContainer container = new GenericContainer("ubuntu")) {30 container.start();31 System.out.println("container = " + container);32 }33 }34}35container = GenericContainer (image name: ubuntu, container id: 0c7c1d8d9b2a)36import org.testcontainers.containers.GenericContainer;37public class GenericContainerDemo {38 public static void main(String[] args) {39 System.out.println("GenericContainer class demo");40 try (GenericContainer container = new GenericContainer("ubuntu")) {41 container.withExposedPorts(80);42 container.start();43 System.out.println("container = " + container);44 }45 }46}47container = GenericContainer (image name: ubuntu

Full Screen

Full Screen

Versioning

Using AI Code Generation

copy

Full Screen

1import org.testcontainers.utility.Versioning;2public class VersioningDemo {3 public static void main(String[] args) {4 System.out.println(Versioning.getVersion());5 System.out.println(Versioning.getLatestVersion());6 }7}

Full Screen

Full Screen

Versioning

Using AI Code Generation

copy

Full Screen

1import org.testcontainers.utility.Versioning;2class 1 {3public static void main(String args[]) {4System.out.println(Versioning.getVersion());5}6}

Full Screen

Full Screen

Versioning

Using AI Code Generation

copy

Full Screen

1import org.testcontainers.utility.Versioning;2class Test{3public static void main(String args[]){4System.out.println("Versioning class: "+Versioning.getVersion());5}6}

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Testcontainers-java automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used methods in Versioning

Test Your Web Or Mobile Apps On 3000+ Browsers

Signup for free

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful