Posts

A program and test to merge two lists whose length and item values are in the range 1 to 10,000 inclusive

import org.testng.annotations.DataProvider; import org.testng.annotations.Test; import java.util.*; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ThreadLocalRandom; import java.util.stream.Collectors; import java.util.stream.Stream; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertTrue; public class MergerTest { private static final int MIN = 1; private static final int MAX = 10000; @DataProvider(parallel = true) public Object[][] data() { int[] one = new int[]{1, 2, 3, 4, 10, 20, 30}; int[] two = new int[]{20, 30, 1, 2, 1, 3, 4, 4, 5}; int[] dynamicOne = ThreadLocalRandom .current().ints(MIN, MAX + 1).limit(MAX).toArray(); int[] dynamicTwo = ThreadLocalRandom .current().ints(MIN, MAX + 1).limit(MAX).toArray(); int[] sameOne = new int[]{7, 7, 7, 7, 7, 7, 7}; int[] diffOne = new int[]{1, 2, 3, 4, 5, 6, 7};

GemfireConfig

package com.mridul.software.automation.spring.configuration; import com.gemstone.gemfire.cache.Region; import com.gemstone.gemfire.cache.client.ClientCache; import com.gemstone.gemfire.cache.client.ClientCacheFactory; import com.gemstone.gemfire.cache.client.ClientRegionShortcut; import com.gemstone.gemfire.internal.concurrent.ConcurrentHashSet; import com.mridul.software.automation.spring.context.properties.gemfire.GemfireCustomProperties; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.data.gemfire.GemfireTemplate; import org.springframework.data.gemfire.repository.config.EnableGemfireRepositories; import javax.annotation.PreDestroy; import java.util.Map; import java.util.

FileSystemUtils

package com.mridul.software.automation.spring.context.utils; import lombok.extern.slf4j.Slf4j; import org.apache.commons.io.FileUtils; import org.springframework.stereotype.Component; import java.io.File; @Slf4j @Component public class FileSystemUtils { public void deleteFileIfExistsAndReCreate(final String fileName) { try { deleteFileIfExists(fileName); FileUtils.touch(new File(fileName)); } catch (final Exception e) { log.debug("File {} could not be created due to {}", fileName, e); } } public void deleteFileIfExists(final String fileName) { try { File file = new File(fileName); if (file.exists()) { org.springframework.util.FileSystemUtils.deleteRecursively(file); log.debug("Delete file : {}", fileName); } } catch (final Exception e) { log.debug("File {} could not be created due to {}", fileName, e);

Report

package com.mridul.software.automation.spring.context.properties.extent; import lombok.Data; import org.apache.commons.lang3.StringUtils; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.context.annotation.Configuration; import org.springframework.validation.annotation.Validated; import javax.validation.constraints.NotNull; @Configuration @ConfigurationProperties(prefix = "extent.report") @Validated @Data public class Report { @NotNull private String fileName; @NotNull private Screenshot screenshot; @Data public static class Screenshot { @NotNull private String filePath; @NotNull private Test test; @Data public static class Test { @NotNull private Enable enable; //this parameter is set in extent test listener private static final ThreadLocal<String> METHOD_NAME =

ExtentLoggingClientHttpRequestInterceptor

package com.mridul.software.automation.rest.interceptors; import com.aventstack.extentreports.ExtentTest; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.JsonObject; import com.google.gson.JsonParser; import lombok.extern.slf4j.Slf4j; import org.springframework.http.HttpRequest; import org.springframework.http.client.ClientHttpRequestExecution; import org.springframework.http.client.ClientHttpRequestInterceptor; import org.springframework.http.client.ClientHttpResponse; import org.springframework.util.StreamUtils; import java.io.IOException; import java.nio.charset.Charset; import java.util.Objects; @Slf4j public class ExtentLoggingClientHttpRequestInterceptor implements ClientHttpRequestInterceptor { private static final ThreadLocal<ExtentTest> TEST_THREAD_LOCAL = new ThreadLocal<>(); public void setExtentTest(ExtentTest test) { TEST_THREAD_LOCAL.set(test); }

AbstractJson

package com.mridul.software.automation.rest.domain; import com.fasterxml.jackson.annotation.JsonAutoDetect; import com.fasterxml.jackson.annotation.PropertyAccessor; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectWriter; import lombok.extern.slf4j.Slf4j; @Slf4j public abstract class AbstractJson { private static final ObjectMapper MAPPER = new ObjectMapper() .setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY); private static final ObjectWriter WRITER = MAPPER.writerWithDefaultPrettyPrinter(); private String toJson() { String json = null; try { json = WRITER.writeValueAsString(this); } catch (final Exception e) { throw new RuntimeException("Not able to serialize to json : " + e); } return json; } public final <T extends AbstractJson> T fromJson(String json, Class<T> clazz) { T t = nul

ExtentLoggingRestTemplateCustomizer

package com.mridul.software.automation.rest.customizers; import com.mridul.software.automation.rest.interceptors.ExtentLoggingClientHttpRequestInterceptor; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.web.client.RestTemplateCustomizer; import org.springframework.web.client.RestTemplate; @Slf4j public class ExtentLoggingRestTemplateCustomizer implements RestTemplateCustomizer { @Autowired private ExtentLoggingClientHttpRequestInterceptor interceptor; @Override public void customize(RestTemplate restTemplate) { restTemplate.getInterceptors().add(interceptor); } }