Skip to content

Instantly share code, notes, and snippets.

View BjoernKW's full-sized avatar

Björn Wilmsmann BjoernKW

View GitHub Profile
@BjoernKW
BjoernKW / SecurityContextFactory.java
Last active February 21, 2022 10:40
Factory for minimal JUnit test setup with security context and a mocked user
package com.bjoernkw.testing;
import org.springframework.security.authentication.TestingAuthenticationToken;
import org.springframework.security.core.context.SecurityContextHolder;
public class SecurityContextFactory {
public static void createSecurityContext(String username) {
SecurityContextHolder.setContext(
SecurityContextHolder.createEmptyContext()
@BjoernKW
BjoernKW / MinimalMockUserTest.java
Last active February 21, 2022 10:40
Minimal JUnit test setup with security context and a mocked user
@Test
void testMethod() throws Exception {
SecurityContextHolder.setContext(
SecurityContextHolder.createEmptyContext()
);
SecurityContextHolder.getContext().setAuthentication(
new TestingAuthenticationToken("TEST_USER", null)
);
}
@BjoernKW
BjoernKW / HttpToHttpsRedirectConfig.java
Last active November 20, 2019 15:35
http to https redirect with Spring Cloud Gateway
package com.bjoernkw.gateway;
@Configuration
public class HttpToHttpsRedirectConfig {
@Value("${server.port}")
private Integer gatewayPort;
@PostConstruct
public WebServerFactoryCustomizer serverFactoryCustomizer() {
@BjoernKW
BjoernKW / gist:c2581ab5a6a4c5f92cfffd4fcbe25ff9
Created March 30, 2019 13:39
Angular CLI command for building an app with base href
ng build --base-href /ROOT_DIRECTORY/ --deploy-url /ROOT_DIRECTORY/ --prod
@BjoernKW
BjoernKW / using-angular2-logger-in-production.md
Created August 17, 2018 11:42
Using angular2-logger in production
import { Logger, Options } from 'angular2-logger/core';

...

{
  provide: Options,
  useValue: {
    store: false
 }
@BjoernKW
BjoernKW / angular-unit-tests-specs-dependency-management.md
Last active August 15, 2018 18:30
Dependency management for Angular unit tests using TestModuleMetadata

some.component.spec.ts:

import { TestModuleMetadata } from '@angular/core/testing';
import { createOtherTestModuleMetadata } from 'other.component.spec';
import { compileTestModuleMetadata } from 'app.module';

...

export function createSomeComponentTestModuleMetadata(): TestModuleMetadata {
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-activemq</artifactId>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-broker</artifactId>
</dependency>
@BjoernKW
BjoernKW / NextSequenceService.java
Last active December 2, 2019 14:29
Next sequence with MongoDB
import static org.springframework.data.mongodb.core.FindAndModifyOptions.options;
import static org.springframework.data.mongodb.core.query.Criteria.where;
import static org.springframework.data.mongodb.core.query.Query.query;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoOperations;
import org.springframework.data.mongodb.core.query.Update;
import org.springframework.stereotype.Service;
import com.model.CustomSequences;
Verifying that +bjoernkw is my blockchain ID. https://onename.com/bjoernkw
@BjoernKW
BjoernKW / keybase.md
Created September 18, 2014 19:45
keybase.md

Keybase proof

I hereby claim:

  • I am BjoernKW on github.
  • I am bjoernkw (https://keybase.io/bjoernkw) on keybase.
  • I have a public key whose fingerprint is 6222 87E1 DE98 9114 AED0 2999 B658 5F6F 4206 A142

To claim this, I am signing this object: