-
-
Notifications
You must be signed in to change notification settings - Fork 197
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
218 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
modules/jooby-jte/src/main/java/io/jooby/internal/jte/JteModelEncoder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* Jooby https://jooby.io | ||
* Apache License Version 2.0 https://jooby.io/LICENSE.txt | ||
* Copyright 2014 Edgar Espina | ||
*/ | ||
package io.jooby.internal.jte; | ||
|
||
import java.nio.charset.StandardCharsets; | ||
|
||
import edu.umd.cs.findbugs.annotations.NonNull; | ||
import edu.umd.cs.findbugs.annotations.Nullable; | ||
import gg.jte.models.runtime.JteModel; | ||
import io.jooby.Context; | ||
import io.jooby.buffer.DataBuffer; | ||
|
||
public class JteModelEncoder implements io.jooby.MessageEncoder { | ||
@Nullable @Override | ||
public DataBuffer encode(@NonNull Context ctx, @NonNull Object value) throws Exception { | ||
if (value instanceof JteModel jte) { | ||
var buffer = ctx.getBufferFactory().allocateBuffer(); | ||
var output = new DataBufferOutput(buffer, StandardCharsets.UTF_8); | ||
jte.render(output); | ||
return buffer; | ||
} | ||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
modules/jooby-jte/src/test/java/io/jooby/jte/Issue3602.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* Jooby https://jooby.io | ||
* Apache License Version 2.0 https://jooby.io/LICENSE.txt | ||
* Copyright 2014 Edgar Espina | ||
*/ | ||
package io.jooby.jte; | ||
|
||
import static org.mockito.ArgumentMatchers.isA; | ||
import static org.mockito.Mockito.*; | ||
|
||
import java.util.Map; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import gg.jte.TemplateOutput; | ||
import gg.jte.models.runtime.JteModel; | ||
import io.jooby.Context; | ||
import io.jooby.buffer.DataBuffer; | ||
import io.jooby.buffer.DataBufferFactory; | ||
import io.jooby.internal.jte.JteModelEncoder; | ||
|
||
public class Issue3602 { | ||
|
||
@Test | ||
public void shouldRenderJteModel() throws Exception { | ||
var bufferFactory = mock(DataBufferFactory.class); | ||
var buffer = mock(DataBuffer.class); | ||
when(bufferFactory.allocateBuffer()).thenReturn(buffer); | ||
|
||
var attributes = Map.<String, Object>of("foo", 1); | ||
var ctx = mock(Context.class); | ||
when(ctx.getBufferFactory()).thenReturn(bufferFactory); | ||
when(ctx.getAttributes()).thenReturn(attributes); | ||
|
||
var model = mock(JteModel.class); | ||
|
||
var engine = new JteModelEncoder(); | ||
engine.encode(ctx, model); | ||
|
||
verify(model, times(1)).render(isA(TemplateOutput.class)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters