How the return type of intercept() is used by struts? - struts2

I am not able to understand the concept behind the return type of intercept().Is it any time related to the return type of actionInvocationInstance.invoke().Need guidance.Thanks in advance.

It's a String, and should be the name of a result.
It may be the result from invoke, or an interceptor's result that "intercepts" the action invocation, e.g., the workflow interceptor returns "input" on a validation error.

It isn't related, but the ActionInvocation::invoke() can return a result code which is suitable to return by the interceptor's intercept method. It's up to you to decide which result code to return by the interceptor, but the result code type is a String defined as a return type by the method Interceptor::intercept(). Note, that a result code corresponds to the result name in the action config, and a result with such name should be available to the configuration at runtime.

Related

Dart Generic Function with Subtype function call

I am not sure if this is even possible but here's my setup:
I have basically 2 Maps holding a special identifier to get some objects.
these identifier is like a versioning number, i may have data in version 8 that belongs to meta version 5. But at the same time, Meta versions up to 10 may exist and not every meta version holds information about every data, so here's where the _filter kicks in.
The filter is able to find to any given value the correct object. So far so good.
My question belongs to the following: (last codeline)
how am i able to say "if you have no matching candidate, generate me a default value"
For this purpose, i tried to force a named constructor with a super class for "Data" and "Meta" called "BasicInformation".
But even if i implement this, how do i call something like T.namedConstructor(); ?
class Repo{
Map<int, Data> mapData;
Map<int, Meta> mapMeta;
Data getData(int value)
{
return _filter<Data>(mapData, value);
}
Meta getMeta(int value)
{
return _filter<Data>(mapMeta, value);
}
T _filter<T extends BasicInformation>(Map<int, T>, int value)
{
//fancy filtering technique
//....
//speudo code
if (found) return map[found]; //speudo code
else return T.generateDefault();
}
}
I've found the following stackoverflow entry: Calling method on generic type Dart
which says, this is not possible without adding a function call.

Why do I need to return null for functions with nullable return type?

I get a warning in this code:
Future<int?> foo() async {
if (someCondition) return 42;
}
This function has a nullable return type of 'FutureOr<int?>', but ends without returning a value.
I'm telling Dart that the Future may complete with a nullable type int?, so why is that I've to explicitly return null to get away with the warning?
It's a warning, not an error. Warnings are for things that are technically legal but very likely are programming mistakes. It's much more likely that someone writing that code forgot to handle a code path than it is that they intentionally wanted an implicit return null. An explicit return null additionally makes intent clear and thus is more readable.

Language-ext: chain Either<L, R> with Option?

I am just starting with language-ext, trying to use it in my Azure Function.
In this function, I first parse/validate the POSTed data from the HTTP request using some validator.
This validator returns an Either<ValidationErrors, RequestModel>.
Then I would like to chain onto the either result a service call that should use the request model to grab some data from an API an return an Option.
At the end of the chain I would then like to return an IActionResult BadRequest if there were ValidationErrors in the first step, or otherwise perform a Match on the result of the service call Option to either return a NotFoundResult or ObjectResult.
The issue I run into is that if I want to chain my service call (using Bind, or BiBind) after the Either<ValidationErrors, GetRequestModel>, then the signature of my service method must be some Either<ValidationErrors, ...>, which is incorrect, since my service method has nothing to do with ValidationErrors. It should just return an Option.
So I guess my question is how can preserve any ValidationErrors until the end of the chain, and be able to chain my service call with a Option signature onto an Either?
You have to decide what the result of your chained expression is.
Option:
var maybeResult = from validated in GetValidationResult(...).ToOption()
from apiResult in ApiCall(...)
select apiResult;
Either:
var resultOrError = from validated in GetValidationResult(...)
from apiResult in ApiCall(...).ToEither(*LEFT*)
select apiResult;
You have to replace *LEFT* by some error value or error generating function returning same type like left type of GetValidationResult.
Replace above pseudo code with your own code and look at the return types of the functions used above to see what's going on.
The reason why you need a common left type is that the bind operation can return some left (error) of first (GetValidationResult) or second (ApiCall) function call -- or right of your last (ApiCall) function if your reach successful end of your chain.
Recommendation: If you mix different left (error) return types you might want to use some thing like LanguageExt's built-in Error type or maybe just a plain string (or Exception).
Either with string as error type:
var resultOrError = from validated in GetValidationResult(...).MapLeft(Prelude.toString)
from apiResult in ApiCall(...).ToEither("api call failed")
select apiResult;
Additional note: I use LINQ style here, you can use method style:
var resultOrError = GetValidationResult(...)
.MapLeft(Prelude.toString)
.Bind(validated => ApiCall(...)
.ToEither("api call failed"));

Matching a method signature with a unknown parameter in a mocked class

I have this method:
Future<Either<Failure, WorkEntity>> updateWorkEntity({int id, String title, TimeType timeType, int times, DateTime executed})
that is being called like this:
repository.updateWorkEntity(id: workEntity.id, executed: DateTime.now())
the id I can control in a test, but the "DateTime.now()" I ofcourse can not. What I tried was this in my test:
when(repository.updateWorkEntity(id: expected.id, executed: any)).thenAnswer((_) async => Right(expected));
to be able to make my mock return a object for my test, by using "any" in the place of the "DateTime.now()", but I get this error:
Invalid argument(s): The "any" argument matcher is used outside of
method stubbing (via when) or verification (via verify or
untilCalled). This is invalid, and results in bad behavior during
the next stubbing or verification.
So I guess I can not use any here, but then how do I get my mock to return an object when I do not control one of the input parameters?
Thank you
Søren
Use executed: anyNamed('executed') instead of executed: any

Asserting return type of MVC Controller Action

How can you assert that an expected type is returned when it is wrapped up in a System.RuntimeType?
As part of a larger unit test to verify that an action has the correct parameters and action filters assigned I'm asserting against a populated instance of MethodInfo. When I assert against "action.ReturnParameter" it fails as it's saying the type is System.RunTimeType. Whilst I understand that this is a wrapper around the expected type, I just can't seem to find a way to assert that the wrapped instance is of the expected type - the best method that I've come up with so far is to assert against name or full name, but that's horrible as it's just using "magic strings".
Can anyone help? As my Google searches haven't turned up anything useful, I'm guessing it's got a really easy solution, I'm just not seeing it.
The code is as follows:
[TestMethod]
public void CheckActionFilterSet()
{
MethodInfo action = new CustomerController((new MockHttpContext()).Object)
.GetType().GetMethods(BindingFlags.Public | BindingFlags.Instance)
.Where(mi => mi.Name.Equals("Search")).First();
Assert.That(action.ReturnParameter.ParameterType, Is.InstanceOf(typeof(ViewResult)), "View Result should be of expected type");
}
Exception message is:
View Result should be of expected type
Expected: instance of
<System.Web.Mvc.ViewResult>
But was:
<System.RuntimeType>
Just call the controller method and check the type of the object that is returned:
var result = new CustomerController((new MockHttpContext()).Object).Search(....);
Assert.That(result, Is.InstanceOf(typeof(ViewResult)), "View Result should be of expected type");
You can also check the values of ViewData / model if you want to...

Resources