-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
we support bifs and components and whatever now
- Loading branch information
Showing
6 changed files
with
150 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/** | ||
* [BoxLang] | ||
* | ||
* Copyright [2024] [Ortus Solutions, Corp] | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the | ||
* License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" | ||
* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language | ||
* governing permissions and limitations under the License. | ||
*/ | ||
package ortus.boxlang.web.bifs; | ||
|
||
import io.undertow.server.HttpServerExchange; | ||
import ortus.boxlang.runtime.bifs.BIF; | ||
import ortus.boxlang.runtime.bifs.BoxBIF; | ||
import ortus.boxlang.runtime.context.IBoxContext; | ||
import ortus.boxlang.runtime.scopes.ArgumentsScope; | ||
import ortus.boxlang.runtime.scopes.Key; | ||
import ortus.boxlang.runtime.types.Argument; | ||
import ortus.boxlang.web.context.WebRequestBoxContext; | ||
|
||
@BoxBIF | ||
public class Forward extends BIF { | ||
|
||
/** | ||
* Constructor | ||
*/ | ||
public Forward() { | ||
super(); | ||
declaredArguments = new Argument[] { | ||
new Argument( true, Argument.STRING, Key.template ) | ||
}; | ||
} | ||
|
||
/** | ||
* | ||
* Leads the request to a different page. | ||
* This function acts like the location functionality except that the relocation is done directly on the server and not the browser | ||
* | ||
* @param context The context in which the BIF is being invoked. | ||
* @param arguments Argument scope for the BIF. | ||
* | ||
* @argument.template The logical path to which the request should be forwarded to. | ||
* | ||
*/ | ||
@SuppressWarnings( "deprecation" ) | ||
public Object _invoke( IBoxContext context, ArgumentsScope arguments ) { | ||
String templatePath = arguments.getAsString( Key.template ); | ||
WebRequestBoxContext requestContext = context.getParentOfType( WebRequestBoxContext.class ); | ||
HttpServerExchange exchange = requestContext.getExchange(); | ||
|
||
exchange.setRequestPath( templatePath ); | ||
exchange.setRelativePath( templatePath ); | ||
exchange.dispatch(); | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package ortus.boxlang.web.bifs; | ||
|
||
import static org.junit.Assert.assertThrows; | ||
|
||
import org.junit.jupiter.api.AfterAll; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Disabled; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import ortus.boxlang.runtime.BoxRuntime; | ||
import ortus.boxlang.runtime.context.IBoxContext; | ||
import ortus.boxlang.runtime.context.ScriptingRequestBoxContext; | ||
import ortus.boxlang.runtime.scopes.IScope; | ||
import ortus.boxlang.runtime.scopes.Key; | ||
import ortus.boxlang.runtime.scopes.VariablesScope; | ||
import ortus.boxlang.runtime.types.exceptions.BoxRuntimeException; | ||
|
||
public class ForwardTest { | ||
|
||
static BoxRuntime runtime; | ||
IBoxContext context; | ||
IScope variables; | ||
static Key result = new Key( "result" ); | ||
|
||
@BeforeAll | ||
public static void setUp() { | ||
runtime = BoxRuntime.getInstance( true ); | ||
} | ||
|
||
@AfterAll | ||
public static void teardown() { | ||
} | ||
|
||
@BeforeEach | ||
public void setupEach() { | ||
// TODO: Brad you need to simulate the web request context here please. | ||
context = new ScriptingRequestBoxContext( runtime.getRuntimeContext() ); | ||
variables = context.getScopeNearby( VariablesScope.name ); | ||
} | ||
|
||
@Test | ||
@DisplayName( "It should fail if the template argument is not provided" ) | ||
public void testNoTemplate() { | ||
// @formatter:off | ||
assertThrows( BoxRuntimeException.class, () -> { | ||
runtime.executeSource( | ||
""" | ||
forward(); | ||
""", | ||
context ); | ||
} ); | ||
// @formatter:on | ||
} | ||
|
||
@Test | ||
@Disabled( "Until Brad figures out how to do web request context tests" ) | ||
@DisplayName( "Forward to a different page" ) | ||
public void testForward() { | ||
// @formatter:off | ||
runtime.executeSource( | ||
""" | ||
forward( template: "/some/path" ); | ||
""", | ||
context ); | ||
// @formatter:on | ||
} | ||
|
||
} |