Skip to content

Instantly share code, notes, and snippets.

View willianantunes's full-sized avatar
🎯
Focusing

Willian Antunes willianantunes

🎯
Focusing
View GitHub Profile
@willianantunes
willianantunes / HttpConnectProxyFactory.java
Created October 9, 2018 22:00
Connection to a SOCKET SERVER via HTTP proxy
package com.mysql.cj.protocol;
import com.mysql.cj.conf.PropertyDefinitions;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.net.InetSocketAddress;
import java.net.Socket;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.util.UriComponentsBuilder;
import java.net.URI;
import java.util.Optional;
import static java.lang.String.join;
import static java.util.Arrays.asList;
/**
<plugin>
<groupId>com.github.searls</groupId>
<artifactId>jasmine-maven-plugin</artifactId>
<version>3.0-alpha-01</version>
<executions>
<execution>
<goals>
<goal>test</goal>
</goals>
</execution>
@Aspect
@Component
public class SampleControllerAspect {
private static final Logger LOGGER = LoggerFactory.getLogger(SampleControllerAspect.class);
@Around("execution(* br.com.globo.controller.SampleController.sample(String)) && args(honestSampleHeader)")
public ModelAndView aroundWallMethod(ProceedingJoinPoint proceedingJoinPoint, String honestSampleHeader) throws Throwable {
LOGGER.debug("What was intercepted: {}", honestSampleHeader);
@Controller
public class SampleController {
private static final Logger LOGGER = LoggerFactory.getLogger(SampleController.class);
@Autowired
private SampleService sampleService;
@GetMapping(REQUEST_PATH_SAMPLE)
public ModelAndView sample(@RequestHeader(HONEST_SAMPLE_HEADER) String honestSampleHeader) {
describe("Regras para atender demandas específicas de testes honestos", () => {
var sampleJasmineController;
beforeEach(() => {
ScenarioBuilder.prepareView();
sampleJasmineController = new SampleJasmineController();
});
@PostMapping(path = REQUEST_PATH_JASMINE, produces = APPLICATION_JSON_VALUE)
public ResponseEntity<?> jasmine(@RequestParam(HONEST_JASMINE_AJAX_PARAMETER) Optional<String> sample) throws InterruptedException {
var maybeEmptySample = sample.map(s -> s.isEmpty()? null : s);
LOGGER.info("Looking for {}", maybeEmptySample);
TimeUnit.SECONDS.sleep(2);
return ok(new Object() {
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<title>Jasmine Honesto</title>
<meta charset="utf-8"/>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
</head>
<body>
class SampleJasmineController {
constructor(serviceUrl) {
let $ = document.querySelector.bind(document);
this._service = new SampleJasmineService(serviceUrl);
this._message = $('p.message');
this._btnSubmit = $('form input[type=submit]');
class SampleJasmineService {
constructor(serviceUrl) {
this._http = new HttpService();
this._servicoUrl = serviceUrl;
}
consult(message) {