Skip to content

Commit

Permalink
add details when a resource is missing + do not fail on file already …
Browse files Browse the repository at this point in the history
…exists (#4184)
  • Loading branch information
iliyan-velichkov authored Jul 31, 2024
1 parent 5691269 commit bc6e3f5
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 94 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
*/
package org.eclipse.dirigible.componenets.api.http;

import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import java.io.IOException;
import java.util.Base64;
import jakarta.servlet.Filter;
import jakarta.servlet.FilterChain;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.eclipse.dirigible.components.engine.javascript.service.JavascriptService;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
Expand All @@ -34,11 +34,13 @@
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.filter.OncePerRequestFilter;
import jakarta.servlet.Filter;
import jakarta.servlet.FilterChain;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.util.Base64;

import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

@ExtendWith(SpringExtension.class)
@SpringBootTest
Expand Down Expand Up @@ -154,15 +156,6 @@ public void executeSessionTest() throws Exception {
.andExpect(status().is2xxSuccessful());
}

@Test
public void executeRSTest() throws Exception {
mockMvc.perform(get("/services/js/http-tests/rs-define-request-handlers.js").header(HttpHeaders.AUTHORIZATION,
"Basic " + Base64.getEncoder()
.encodeToString("user:password".getBytes())))
.andDo(print())
.andExpect(status().is2xxSuccessful());
}

@Configuration
static class Config {
@Autowired
Expand All @@ -183,6 +176,7 @@ PasswordEncoder passwordEncoder() {

}


static class HttpResponseHeaderHandlerFilter extends OncePerRequestFilter {

@Override
Expand All @@ -197,7 +191,6 @@ protected void doFilterInternal(HttpServletRequest request, HttpServletResponse
}



@SpringBootApplication
static class TestConfiguration {

Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
import org.eclipse.dirigible.repository.api.IRepository;
import org.eclipse.dirigible.repository.api.IRepositoryStructure;
import org.eclipse.dirigible.repository.api.IResource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import java.io.IOException;
Expand All @@ -31,6 +33,8 @@
@CalledFromJS
public class DirigibleSourceProvider implements JavascriptSourceProvider {

private static final Logger LOGGER = LoggerFactory.getLogger(DirigibleSourceProvider.class);

/**
* Gets the absolute source path.
*
Expand Down Expand Up @@ -184,15 +188,23 @@ protected String createLookupPath(String filePathString) {
* @return the path
*/
public Path unpackedToFileSystem(Path pathToUnpack, Path pathToLookup) {
String path = "/META-INF/dirigible/" + pathToLookup.toString();
try (InputStream bundled = this.getClass()
.getResourceAsStream("/META-INF/dirigible/" + pathToLookup.toString())) {
.getResourceAsStream(path)) {
Files.createDirectories(pathToUnpack.getParent());
Files.createFile(pathToUnpack);
if (!Files.exists(pathToUnpack)) {
LOGGER.debug("File [{}] does NOT exist. Will be created", pathToUnpack);
Files.createFile(pathToUnpack);
} else {
LOGGER.debug("File [{}] exists and will NOT be created", pathToUnpack);
}
if (null == bundled) {
throw new IllegalStateException("Failed to load resource from path [" + path + "]");
}
Files.copy(bundled, pathToUnpack, StandardCopyOption.REPLACE_EXISTING);
} catch (IOException e) {
throw new RuntimeException(e);
return pathToUnpack;
} catch (IOException ex) {
throw new RuntimeException("Failed to unpack [" + pathToLookup + "] to [" + pathToUnpack + "]", ex);
}

return pathToUnpack;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { user } from "sdk/security";
import { assertEquals, test } from "sdk/junit"

test('get-user-test', () => {
assertEquals('Unexpected user', user.getName(), 'guest');
});

0 comments on commit bc6e3f5

Please sign in to comment.