Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mock API requires resource extension #8085

Closed
anatol-sialitski opened this issue May 14, 2020 · 1 comment
Closed

Mock API requires resource extension #8085

anatol-sialitski opened this issue May 14, 2020 · 1 comment
Assignees
Labels
Milestone

Comments

@anatol-sialitski
Copy link
Contributor

anatol-sialitski commented May 14, 2020

CURRENT SITUATION

In order to mock parts of API we should register internal services in test. That is very difficult for end-user, because he has to know internal logic of services.

For example, we want to mock content lib.

t.mock('/lib/xp/content', {
  get: function(params) {
    return { ... }
  }
});

In this case we have to add mock for services which are called in the get method

private ContentTypeService contentTypeService;
private MixinService mixinService;
private XDataService xDataService;

@Override
public void initialize()
    throws Exception
{
    super.initialize();

    this.contentTypeService = Mockito.mock( ContentTypeService.class );
    this.mixinService = Mockito.mock( MixinService.class );
    this.xDataService = Mockito.mock( XDataService.class );

    addService( ContentTypeService.class, this.contentTypeService );
    addService( MixinService.class, this.mixinService );
    addService( XDataService.class, this.xDataService );

    Content content = ... // build content here

    Mockito.when(contentService.getById( Mockito.any( ContentId.class ) ) ).thenReturn( content );
    Mockito.when(contentService.getByPath( Mockito.any( ContentPath.class ) ) ).thenReturn( content );
}

SHOULD BE

When some method is mocked, then a call of real method of service/lib should be avoided and replaced with a method decorator.

Details of implementation should be discussed.

@anatol-sialitski anatol-sialitski self-assigned this May 14, 2020
@alansemenov alansemenov added Improvement To Be Discussed Issues that require additional discussion labels May 14, 2020
@rymsha rymsha added Bug and removed Improvement To Be Discussed Issues that require additional discussion labels May 20, 2020
@rymsha
Copy link
Contributor

rymsha commented May 20, 2020

rebranded to a bug, because mock was supposed to work similarly to require

@rymsha rymsha changed the title Improve mock method for Test Framework mock method does not handle resources without extension May 20, 2020
@alansemenov alansemenov changed the title mock method does not handle resources without extension Mock API requires resource extension May 22, 2020
@alansemenov alansemenov added this to the 7.3.0 milestone May 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants